我已经测试了所有的代码,但每当我尝试使用传输命令时,我都会得到这个错误。有人能告诉我如何修复它吗,我对所有这些都很陌生。
这是错误code-error的图像
我也收到了这个错误
出现异常: TypeError不支持-的操作数类型:'float‘和'tuple’行30,在转帐balance=(余额,金额)+余额行58,在转帐(余额,金额)
name=input("write your name? ")
balance=float(input("Your current balance? "))
def printMenu():
print(name,"Welcome to the atm")
print(""""Pick from the following
'b'(balance)
'd'(deposit)
'w'(withdraw)
't'(transfer)
'q'(quit)""")
def getTransaction():
transaction=str(input("What would you like to do? "))
return transaction
def withdraw(bal,amt):
global balance
balance=bal-amt
if balance<0:
balance=balance-10
def formatCurrency(amt):
return "SR%.2f" %amt
def transfer (bal,amt):
global balance
balance=(bal-amt) + balance
if balance<0:
print("You dont have enoung funds for that: ")
printMenu()
command=str(getTransaction())
while command!="q":
if (command=="b"):
print(name,"Your current balance is",formatCurrency(balance))
printMenu()
command=str(getTransaction())
elif (command=="d"):
amount=float(input("Amount to deposit? "))
balance=balance+amount
printMenu()
command=str(getTransaction())
elif (command=="w"):
amount=float(input("Amount to withdraw? "))
withdraw(balance,amount)
printMenu()
command=str(getTransaction())
elif (command=="t"):
Name =print("who would you like to transfer money too")
print (input("write here: "))
amount = print, float(input("write here the amount that you will send: "))
print("You will send {amount}to {Name}")
transfer(balance,amount)
command=str(getTransaction())
else:
print("Incorrect command. Please try again.")
printMenu()
command=str(getTransaction())
print(name,"Thank you for using this atm! See you again soon")发布于 2021-01-11 02:23:18
amount = print, float(input("write here the amount that you will send: "))这一错误行使amount成为一个元组,因此在调用transfer(balance, amount)时出现错误。
不知道您试图在这里实现什么,但它绝对应该更改为
amount = float(input("write here the amount that you will send: "))https://stackoverflow.com/questions/65656838
复制相似问题