“C”, “c”, “coffee” or ANY combination of upper and lower case letters that correctly spells “coffee”, i.e., “Coffee”, “COFFEE”, “coffEE” are acceptable, if doesn't meet requirement program ends, or else the program continues.
Asked
Active
Viewed 242 times
-1
-
2`if input_str.lower() == 'coffee'` – ksbg Oct 02 '18 at 03:04
-
3`if input().lower() in ('c', 'coffee'):` – Steven Rumbalski Oct 02 '18 at 03:04
-
In this case, the suggested answers and comments would work, but if the condition gets complicated enough to warrant the use for regular expression, [then there's a flag to ignore casing](https://stackoverflow.com/a/500870/8557739). – T Tse Oct 02 '18 at 04:13
1 Answers
0
You can use str.lower()
to make the input lowercase for a case-insensitive match:
import sys
expected = 'coffee'
if input('What do you want? ').lower() not in (expected[0], expected):
sys.exit()
print('Right. Continuing...')

blhsing
- 91,368
- 6
- 71
- 106