首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有人能解释一下为什么我的自动柜员机python程序出现这个错误(TypeError:-不支持的操作数类型:'float‘和'tuple')

有人能解释一下为什么我的自动柜员机python程序出现这个错误(TypeError:-不支持的操作数类型:'float‘和'tuple')
EN

Stack Overflow用户
提问于 2021-01-11 02:19:09
回答 1查看 41关注 0票数 0

我已经测试了所有的代码,但每当我尝试使用传输命令时,我都会得到这个错误。有人能告诉我如何修复它吗,我对所有这些都很陌生。

这是错误code-error的图像

我也收到了这个错误

出现异常: TypeError不支持-的操作数类型:'float‘和'tuple’行30,在转帐balance=(余额,金额)+余额行58,在转帐(余额,金额)

代码语言:javascript
复制
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")
EN

回答 1

Stack Overflow用户

发布于 2021-01-11 02:23:18

代码语言:javascript
复制
amount = print, float(input("write here the amount that you will send: "))

这一错误行使amount成为一个元组,因此在调用transfer(balance, amount)时出现错误。

不知道您试图在这里实现什么,但它绝对应该更改为

代码语言:javascript
复制
amount = float(input("write here the amount that you will send: "))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65656838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档