checkIO-ATM问题

给定当前账户总数,后面列表为要取出的钱,然后以以下规则取钱:

1)ATM机的最小单位为5,所以,只能取 那些被5整除的钱;

2)每次取钱收取佣金为0.5+1%

3)每次操作后余额向下取整

 1 # Withdraw without any incident 
 2 # 120 - 10 - 0.5 - 1% = floor(109.4) = 109
 3 # 109 - 20 - 0.5 - 1% = floor(88.3) = 88
 4 # 88 - 30 - 0.5 - 1% = floor(57.2) = 57
 5 from math import floor
 6 def checkio(data):
 7     balance, withdrawal = data
 8     for i in withdrawal:
 9         if i % 5 != 0:
10             continue
11         left = balance - i - 0.5 - .01
12         if left <= 0.5:
13             continue
14         else:
15             balance = left
16         balance = floor(balance)
17     return balance
18 if __name__ == '__main__':
19     assert checkio([120, [10 , 20, 30]]) == 57, 'First'
20     # With one Insufficient Funds, and then withdraw 10 $
21     assert checkio([120, [200 , 10]]) == 109, 'Second'
22     #with one incorrect amount
23     assert checkio([120, [3, 10]]) == 109, 'Third'
24     assert checkio([120, [200, 119]]) == 120 , 'Fourth'
25     assert checkio([120, [120, 10, 122, 2, 10, 10, 30, 1]]) == 56, "It's mixed all base tests"
26     
27     print 'All Ok'

 

posted @ 2012-11-14 11:45  dandingyy  阅读(507)  评论(0编辑  收藏  举报