CodeChef实践挑战-“ ATM”

时间:2019-09-07 10:04:01

标签: python python-3.x

Pooja希望从ATM机上提取X美元。仅当X为5的倍数且Pooja的帐户余额中有足够的现金来执行提款交易(包括银行手续费)时,自动提款机才会接受交易。每次成功取款,银行收取0.50美元。

尝试交易后计算Pooja的帐户余额。输入

正整数0

负数0 <= Y <= 2000,精度为两位数-Pooja的初始帐户余额。输出

尝试进行交易后输出帐户余额,以两位精度的数字给出。如果帐户中没有足够的资金来完成交易,请输出当前的银行余额。

    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

1 个答案:

答案 0 :(得分:0)

您在这里缺少一个条件

  1. 如果 withdrawl_ammount> balance_ammount
  2. ,该怎么办?

修改您的代码,然后重试

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)