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
5 Réponses
0
Have you tried defining like
a = "a, A"
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)
0
both of those unfortunately didn't work :(
but thanks for your help guys @nitesh and @tony
0
found out why. in python 2 you gotta put raw_input
so options = input("crap here")
would be
options = raw_input("crap here")
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...