ATM SCRIPT CODIO-试图了解我的错误。任何见识将不胜感激

时间:2018-12-02 22:08:21

标签: python codio

我是编码的新手,我试图了解为什么会收到此错误。这是某种间距错误,我已经研究了很长时间了。任何见识将不胜感激。我也在codio上插入了我的错误。

实际输出:

  

您想做什么?

     

您今天要提取多少钱?提现金额为   $ 100.00,您当前的余额为$ 400.25

     

感谢您与我们合作。

预期输出:

  

您想做什么?

     

您今天要提取多少钱?

     

提款金额为$ 100.00,当前余额为$ 400.25

实际输出:

  

您想做什么?

     

您今天要提取多少钱? $ 700.00大于   您的帐户余额$ 500.25

     

感谢您与我们合作。

预期输出:

  

您想做什么?

     

您今天要提取多少钱?

     

$ 700.00大于您的帐户余额$ 500.25

Codio Error

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.")

2 个答案:

答案 0 :(得分:0)

我认为问题的一部分是“谢谢您与我们合作。”不应该输出消息。另外,似乎测试要求您在输入(通常由用户输入)之后打印换行符。

答案 1 :(得分:0)

enter code hereimport sys

帐户余额

account_balance = float(500.25)

<--------功能转到此处-------------------->

打印平衡功能

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

存款功能

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))

提现功能

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条件语句根据用户输入调用函数

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.")

对于前几张支票,请确保在打印区域(“谢谢您与我们合作。”)中打#号,因为这不应该写。

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

相关问题