0

我是编码新手,我试图了解为什么会出现此错误。这是某种间距错误,我已经为此工作了很长时间。任何见解将不胜感激。我还在 codio 上插入了我的错误。

实际输出:

你想干什么?

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

感谢您使用我们的银行服务。

预期输出:

你想干什么?

你今天想取多少钱?

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

实际输出:

你想干什么?

你今天想取多少钱?700.00 美元大于您的账户余额 500.25 美元

感谢您使用我们的银行服务。

预期输出:

你想干什么?

你今天想取多少钱?

700.00 美元大于您的账户余额 500.25 美元

编码错误

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

2 回答 2

1
enter code hereimport sys

账户余额

account_balance = 浮动(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.")

对于前几张支票,请确保在 print("Thank you for bank with us.") 区域放置一个 # 号,因为它不应该被写入。

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

于 2018-12-03T02:33:38.207 回答
0

我认为部分问题在于“感谢您向我们提供银行服务”。不应该输出消息。此外,测试似乎要求您在输入后打印换行符(通常由用户输入)。

于 2018-12-03T00:20:38.283 回答