0

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"

swift
  • 75
  • 12

2 Answers2

2

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.

Community
  • 1
  • 1
CollinD
  • 7,304
  • 2
  • 22
  • 45
2

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
Mohit S
  • 13,723
  • 6
  • 34
  • 69