我目前正在使用python进行娱乐用途,而且这个ATM脚本运行不正常,请帮忙。
def balance():
balance=7.52
return balance
print("Hi, Welcome to the Atm.")
print("no need for pin numbers, we already know who you are")
print("please selection one of the options given beneath")
print("""
D = Deposit
W = Withdrawal
T = Transfer
B = Balance check
Q = Quick cash of 20$
E = Exit
Please select in the next line.""")
def option():
option = input("which option would you like?:")
return option
input("which option would you like?:")
if option == "D":
print("How much would you like to deposit?")
amount = (int(input("amount:")))
total = amount + balance
答案 0 :(得分:4)
答案 1 :(得分:0)
当剧本问你"你想要哪个选项?:"你必须输入" D"或者' D'而不是D导致输入功能,我认为你应该使用raw_input
你还会遇到另一个问题:
total=amount+balance
你必须为呼叫功能添加()
total=amount+balance()
用这一行:
if option =="D":
原因选项未定义。
option = option()
答案 2 :(得分:0)
def balance():
balance=7.52
return balance
print("Hi, Welcome to the Atm.")
print("no need for pin numbers, we already know who you are")
print("please selection one of the options given beneath")
print("""
D = Deposit
W = Withdrawal
T = Transfer
B = Balance check
Q = Quick cash of 20$
E = Exit
Please select in the next line. """)
def option():
option=input("which option would you like?:")
return option
input("which option would you like?:")
if option =="D":
print("How much would you like to deposit?")
amount=(int(input("amount:")))
total=amount+balance
您需要将代码 正确缩进 ,因此它看起来像这样(查找):
input
仅用于Python 3.x. Python 3.x版本的等价物是raw_input
,即Python 2.x版本。由于存在混淆,不建议对变量和函数使用相同的名称。最好重命名其中一个。如果您使用的是Python 3.x,则需要修复缩进。试试Python 2.7 Docs或Python 3.x Docs