0

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?

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153

1 Answers1

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 _main to the method and return a boolean:
       def trueCheck(response):
        if response == "True":
            return True
        if response == "False":
            return False
CyberCat
  • 957
  • 1
  • 7
  • 10