我是编码的新手,我试图了解为什么会收到此错误。这是某种间距错误,我已经研究了很长时间了。任何见识将不胜感激。我也在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.")
答案 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))
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.")
对于前几张支票,请确保在打印区域(“谢谢您与我们合作。”)中打#号,因为这不应该写。
这是此代码的最终修订版。