为什么这不起作用? "d is not defined"
Why does this not work? "d is not defined"
我目前正在 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
您似乎在使用 Python 2,其中 input
attempts to evaluate what the user types as though it were a Python statement. You should instead use raw_input
没有。
当脚本问你 "which option would you like?:" 你必须键入 "D" 或 'D' 而不是 D 导致输入功能时,我认为你应该使用 raw_input
而且您还会遇到其他问题:
total=amount+balance
调用函数必须加()
total=amount+balance()
加上这一行:
if option =="D":
原因选项未定义。
option = option()
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 or the Python 3.x Docs
我目前正在 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
您似乎在使用 Python 2,其中 input
attempts to evaluate what the user types as though it were a Python statement. You should instead use raw_input
没有。
当脚本问你 "which option would you like?:" 你必须键入 "D" 或 'D' 而不是 D 导致输入功能时,我认为你应该使用 raw_input
而且您还会遇到其他问题:
total=amount+balance
调用函数必须加()
total=amount+balance()
加上这一行:
if option =="D":
原因选项未定义。
option = option()
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 or the Python 3.x Docs