0

Calculator program

Hey I was testing out case insensitive options for a calculator so i did the following options = input ("What would you like to do? Add(a), Subtract (s), Multiply (m): ") if options.lower() == "a": answer = x + y print answer elif options.lower() == "s" answer = x - y print answer and so on. When i test it without the a, s, and m defined it says "nameError 'a' is not defined" but when i define them like a = "a" etc it works but the thing is when i do that caps dont work

29th Dec 2016, 3:10 AM
Eric Reed
Eric Reed - avatar
5 Answers
0
Have you tried defining like a = "a, A"
29th Dec 2016, 3:17 AM
Tony
0
options = input ("What would you like to do? Add(a), Subtract (s), Multiply (m): ") options=str(options) #changed to string if options.lower() == "a": answer = x + y print (answer) elif options.lower() == "s": answer = x - y print (answer)
29th Dec 2016, 3:47 AM
nitesh
0
both of those unfortunately didn't work :( but thanks for your help guys @nitesh and @tony
29th Dec 2016, 4:05 AM
Eric Reed
Eric Reed - avatar
0
found out why. in python 2 you gotta put raw_input so options = input("crap here") would be options = raw_input("crap here")
29th Dec 2016, 4:42 AM
Eric Reed
Eric Reed - avatar
0
Wait, how on earth is it possible for 'a' to be an identifier ? o_O EDIT: even with Python 2 I would think the options.lower() would raise a TypeError rather than a NameError...
30th Dec 2016, 5:55 AM
Amaras A
Amaras A - avatar