def money():
cashin = input("Please insert money: £1 Per Play!")
dif = 1 - cashin
if cashin < 1.0:
print ("You have inserted £", cashin, " you must insert another £", math.fabs(dif))
elif cashin > 1.0:
print ("Please take your change: £", math.fabs(dif))
else:
print ("You have inserted £1")
menu()
def menu():
print ("Please choose an ARTIST: <enter character ID>")
print ("<BEA> - The Beatles")
print ("<MIC> - Michael Jackson")
print ("<BOB> - Bob Marley")
cid = input()
if cid.upper == ("BEA"):
correct = input("You have selected the Beatles, is this correct? [Y/N]:")
if correct.upper() == ("Y"):
bea1()
else:
menu()
elif cid.upper() == ("MIC"):
correct = input("You have selected Michael Jackson, is this correct? [Y/N]:")
if correct.upper() == ("Y"):
mic1()
else:
menu()
elif cid.upper() == ("BOB"):
correct = input("You have selected Bob Marley, is this correct? [Y/N]:")
if correct.upper() == ("Y"):
bob1()
else:
menu()
else:
print ("That is an invalid character ID")
menu()
这是我的自动存储塔代码的一部分
如果我在“选择艺术家”输入中键入“bea”,我的代码会给我一个错误,即没有定义bea。但我不是想把它当作函数或变量?我想使用if语句根据用户的输入来决定要做什么
通常这对我有效,我不知道问题出在哪里。这只是我的一部分代码,如果你需要看到更多让我知道
在Python2.x中,要从提示符获取字符串,请使用^{} 而不是^{} :
Python 2中的
input
函数与Python 3中的input
函数不同。它不返回字符串,但对其求值。在您的例子中,您键入bea
,它尝试将bea
作为表达式求值。但是这个名字没有定义。你知道吗如
input
的文档所述:另外,正如@frostnational在其注释中所指出的那样,您忘记了在下一行实际调用
upper
方法,因此您试图将方法本身与字符串进行比较。你想要什么相关问题 更多 >
编程相关推荐