Input: Список целых чисел: первое значение означает баланс счета, второе значение является списком сумм, которые требуется снять.
Output: Баланс счета после всех операций (integer).
Output: Баланс счета после всех операций (integer).
# Withdraw without any incident # 120 - 10 - 0.5 - 1% (10*0.01) = floor(109.4) = 109 # 109 - 20 - 0.5 - 1% (20*0.01) = floor(88.3) = 88 # 88 - 30 - 0.5 - 1%(30*0.01) = floor(57.2) = 57 checkio([120, [10, 20, 30]]) == 57 checkio([120, [200, 10]]) == 109 checkio([120,[3, 10]]) == 109 checkio([120, [200 , 119]]) == 120 checkio([120, [120, 10, 122, 2, 10, 10, 30, 1]]) == 56
Решение:
from math import floor
def checkio(data):
balance, withdrawal = data
for withdraw in withdrawal:
if not withdraw % 5 and withdraw > 0:
new_balance = floor(balance - withdraw -
0.5 - withdraw * 0.01)
else:
continue
if new_balance >= 0:
balance = new_balance
return int(balance)
if __name__ == '__main__':
assert checkio([120, [10 , 20, 30]]) == 57, 'First'
# With one Insufficient Funds, and then withdraw 10 $
assert checkio([120, [200 , 10]]) == 109, 'Second'
#with one incorrect amount
assert checkio([120, [3, 10]]) == 109, 'Third'
assert checkio([120, [200, 119]]) == 120 , 'Fourth'
assert checkio([120, [120, 10, 122, 2, 10, 10, 30, 1]]) == 56, "It's mixed all base tests"
print('All Ok')
Комментариев нет:
Отправить комментарий