I want to get an input from user. If I want a string as an input, then I can have input("enter your answer")
But if I want the input as a boolean value: True or False ONLY, how can I do it in python?
            Asked
            
        
        
            Active
            
        
            Viewed 578 times
        
    0
            
            
         
    
    
        snakecharmerb
        
- 47,570
- 11
- 100
- 153
 
    
    
        Fazlook Gdn
        
- 3
- 1
- 
                    1see [this](https://stackoverflow.com/a/48817562/9472529) – Yoav Ben Haim Jul 03 '21 at 19:57
1 Answers
0
            You can either:
- Create a separate method that asks for input of strings like "True"or"False"and that use that method as a boolean according to what it returns:
def trueCheck(): response = input("True or False?") if response == "True": return True if response == "False": return False
- Or pass the response from _mainto the method and return a boolean:
def trueCheck(response): if response == "True": return True if response == "False": return False
 
    
    
        CyberCat
        
- 957
- 1
- 7
- 10