Pooja想从ATM取款X $ US。仅当X是5的倍数且Pooja的帐户余额中有足够的现金来执行提款交易(包括银行手续费)时,自动提款机才会接受交易。每次成功取款,银行收取0.50美元。
尝试交易后计算Pooja的帐户余额。输入值
正整数0
非负数0
尝试交易后输出帐户余额,以两位精度的数字给出。如果帐户中没有足够的资金来完成交易,请输出当前的银行余额。
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
我用Python3.x来解决这个程序,我的代码是这样的:
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)
它执行得很好,但是当我提交答案时,结果不正确。谁能帮助我,告诉我我错了。
问题链接:https://www.codechef.com/problems/HS08TEST
最佳答案
您在这里缺少一个条件
如果withdrawl_ammount> balance_ammount怎么办
修改您的代码,然后重试
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)