I'd like to use Python 3's input() function to ask the user a yes or no question. For example:
affirmative = ["", "y", "yes"]
x = input("Continue? [Y/n] ").lower()
if x in affirmative:
# Do something
else:
print("Canceled")
Is there a certain list I should be using for "affirmative" answers? I know Python has things like string.uppercase and string.lowercase for pre-determined lists of variables. Is there a list of answers that should be considered a "yes" answer?
Python's distutils has strtobool which might work for you. Documentation Link.
distutils.util.strtobool(val)
Convert a string representation of truth to true (1) or false (0).
- True values are: y, yes, t, true, on, 1.
- False values are: n, no, f, false, off, 0.
- Raises ValueError otherwise.
But this doesn't exactly fit with the style you're currently hoping for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With