python - 'bea' is not defined? -
this question has answer here:
def money(): cashin = input("please insert money: £1 per play!") dif = 1 - cashin if cashin < 1.0: print ("you have inserted £", cashin, " must insert £", math.fabs(dif)) elif cashin > 1.0: print ("please take change: £", math.fabs(dif)) else: print ("you have inserted £1") menu() def menu(): print ("please choose artist: <enter character id>") print ("<bea> - beatles") print ("<mic> - michael jackson") print ("<bob> - bob marley") cid = input() if cid.upper == ("bea"): correct = input("you have selected beatles, correct? [y/n]:") if correct.upper() == ("y"): bea1() else: menu() elif cid.upper() == ("mic"): correct = input("you have selected michael jackson, correct? [y/n]:") if correct.upper() == ("y"): mic1() else: menu() elif cid.upper() == ("bob"): correct = input("you have selected bob marley, correct? [y/n]:") if correct.upper() == ("y"): bob1() else: menu() else: print ("that invalid character id") menu()
this part of code jukebox
my code giving me error bea not defined if type 'bea' on 'choose artist' input. i'm not trying use function or variable? want use if statement decide based on users input
usually works me, don't know problem is. section of code, if need see more let me know
in python 2.x, string prompt, use raw_input()
instead of input()
:
cid = raw_input()
the input
function in python 2 not equivalent input
in python 3. not return string, evaluates it. in case, type bea
, tries evalueate bea
expression. name not defined.
as mentioned in docs input
:
equivalent
eval(raw_input(prompt))
.
also, @frostnational notes in comment, forgot call upper
method on next line, trying compare method string. want
if cid.upper() == "bea":
Comments
Post a Comment