Is it possible to use python and have a set list of options to choose from?
For example when asked for input let you choose "Yes" "No" or "Maybe"
Is it possible to use python and have a set list of options to choose from?
For example when asked for input let you choose "Yes" "No" or "Maybe"
I suspect that a bit of searching would've done you some good on this one.
See answer to extremely similar question here https://stackoverflow.com/a/3041990/5298696
Adding a "Maybe" option would be a trivial edit, provide an update if you need assistance with that.
You can use this function:
def yesno_to_bool(s):
s = s.lower()
if s == "yes":
return True
elif s == "no":
return False
Which works like this:
>>> yesno_to_bool("yes")
True
>>> yesno_to_bool("no")
False
>>> yesno_to_bool("Maybe")
None