我是编码新手,我试图了解为什么会出现此错误。这是某种间距错误,我已经为此工作了很长时间。任何见解将不胜感激。我还在 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.")