Pooja希望从ATM机上提取X美元。仅当X为5的倍数且Pooja的帐户余额中有足够的现金来执行提款交易(包括银行手续费)时,自动提款机才会接受交易。每次成功取款,银行收取0.50美元。
尝试交易后计算Pooja的帐户余额。输入
正整数0 负数0 <= Y <= 2000,精度为两位数-Pooja的初始帐户余额。输出 尝试进行交易后输出帐户余额,以两位精度的数字给出。如果帐户中没有足够的资金来完成交易,请输出当前的银行余额。 我用Python3.x来解决这个程序,我的代码是:- 它执行得很好,但是当我提交答案时,结果不正确。谁能帮我告诉我哪里错了。 Example - Successful Transaction
Input: 30 120.00
Output: 89.50
Example - Incorrect Withdrawal Amount (not multiple of 5)
Input: 42 120.00
Output: 120.00
Example - Insufficient Funds
Input: 300 120.00
Output: 120.00
withdrawal_amount, balance_amount = input().split()
withdrawal_amount = int(withdrawal_amount)
balance_amount = float(balance_amount)
if withdrawa`enter code here`l_amount % 5 == 0:
balance_amount = balance_amount - withdrawal_amount - 0.5
print('%.2f' % balance_amount)
else:
print('%.2f' % balance_amount)
答案 0 :(得分:0)
您在这里缺少一个条件
修改您的代码,然后重试
withdrawal_amount, balance_amount = input().split()
withdrawal_amount = int(withdrawal_amount)
balance_amount = float(balance_amount)
if (withdrawal_amount % 5 == 0 and balance_amount>(withdrawal_amount+.5)):
balance_amount = balance_amount - withdrawal_amount - 0.5
print('%.2f' % balance_amount)
else:
print('%.2f' % balance_amount)