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?

1
  • 1
    see this Commented Jul 3, 2021 at 19:57

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.