I am working with Python version 3.7.4. I am working on a piece of code that requires user input in the form of yes or no, as follows:
isValid = input("Is this a previous version? (y/n)")
I would like to convert this yes or no question into a boolean response. I have seen this one possibility that I am interested in implementing:
isValid = False if input("Is this a previous version? (y/n)").lower() == 'n' else True
I also want to account for if the user were to give an input other than y
or n
, though. Ideally, I would like to raise an error if they were to give an input. Could someone show me to how to implement a boolean variable isValid
like this in a concise way, or would I have to create another method that would check the user input? Thank you in advance. I can add more details if needed.