首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ATM脚本CODIO -试图理解我的错误。如有任何见解,将不胜感激。

ATM脚本CODIO -试图理解我的错误。如有任何见解,将不胜感激。
EN

Stack Overflow用户
提问于 2018-12-02 22:08:20
回答 2查看 2.8K关注 0票数 0

我对编码很陌生,我正在努力理解为什么我会收到这个错误。这是某种间距错误,我已经研究了很长一段时间。任何洞察力都将不胜感激。我还在音频中插入了错误。

实际产出:

你想做什么? 你今天想取多少钱?提款金额为100.00美元,您目前的余额为400.25美元。 谢谢你帮我们办理银行业务。

预期产出:

你想做什么? 你今天想取多少钱? 提款金额为100.00美元,当期余额为400.25美元。

实际产出:

你想做什么? 你今天想取多少钱?700.00美元比你的500.25美元的账户余额还多。 谢谢你帮我们办理银行业务。

预期产出:

你想做什么? 你今天想取多少钱? 700.00美元比你的500.25美元的帐户余额还要多。

代码语言:javascript
复制
import sys

#account balance 
account_balance = float(500.25)


#<--------functions go here-------------------->
#printbalance function

def balance():
    print("Your current balance: $%.2f" % account_balance)

#deposit function

def deposit():
     deposit_amount = float(input("How much would you like to deposit? "))
     balance = account_balance - deposit_amount
     print("Deposit amount was $%.2f, current balance is $%.2f" % (deposit_amount, balance))

#withdraw function

def withdraw():
    withdraw_amount = float(input("How much would you like to withdraw today? "))
    if withdraw_amount > account_balance:
        print("$%.2f is greater that your account balance of $%.2f" % (withdraw_amount, account_balance))
    else:
        balance = account_balance - withdraw_amount
        print("Withdraw amount was $%.2f, your current balance is $%.2f" % (withdraw_amount, balance))

#User Input goes here, use if/else conditional statement to call function based on user input

userchoice = input ("What would you like to do?\n")

if (userchoice == "D"):
    deposit()
elif (userchoice == "B"):
    balance()
elif (userchoice == "W"):
    withdraw()


print("Thank you for banking with us.")
EN

回答 2

Stack Overflow用户

发布于 2018-12-03 02:33:38

代码语言:javascript
复制
enter code hereimport sys

帐户余额

account_balance =浮动(500.25)

<-这里的函数

打印平衡函数

代码语言:javascript
复制
def balance():
    print("Your current balance : $%.2f" % account_balance)

存款函数

代码语言:javascript
复制
def deposit():
     deposit_amount = float(input("How much would you like to deposit today?\n"))
     balance = account_balance + deposit_amount
     print("Deposit was $%.2f, current balance is $%.2f" % (deposit_amount,balance))

提取函数

代码语言:javascript
复制
def withdraw():
    withdraw_amount = float(input("How much would you like to withdraw today?\n"))
    if withdraw_amount > account_balance:
    print("$%.2f is greater than your account balance of $%.2f" % (withdraw_amount, 
    account_balance))
else:
    balance = account_balance - withdraw_amount
    print("Withdrawal amount was $%.2f, current balance is $%.2f" % (withdraw_amount, balance))

用户输入在这里,使用if/else条件语句调用基于用户输入的函数

代码语言:javascript
复制
userchoice = input ("What would you like to do?\n")


if (userchoice == "D"):
    deposit()
elif (userchoice == "B"):
    balance()
elif (userchoice == "W"):
    withdraw()


print("Thank you for banking with us.")

对于前几张支票,一定要在印刷品上贴上#标志(“谢谢你和我们一起来银行”)。区域,因为它是不应该写的。

这是对此代码的最终修订。

票数 1
EN

Stack Overflow用户

发布于 2018-12-03 00:20:38

我认为问题的一部分是“谢谢你和我们一起来银行”。消息不应该被输出。此外,测试似乎要求您在输入(通常由用户输入)之后打印一个中断行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53585061

复制
相关文章

相似问题

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