Sichanov

ddd

Nov 30th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. needed_money = float(input())
  2. money_in_hand = float(input())
  3. spending_days_counter = 0
  4. spending_too_many_days = False
  5. total_days = 0
  6. while money_in_hand < needed_money:
  7.     action = input()
  8.     sum = float(input())
  9.     total_days += 1
  10.     if action == "spend":
  11.        money_in_hand -= sum
  12.     if money_in_hand < 0:
  13.         money_in_hand = 0
  14.     spending_days_counter += 1
  15.     if spending_days_counter == 5:
  16.         spending_too_many_days = True
  17.         break
  18.     else:
  19.         money_in_hand += sum
  20.         spending_days_counter = 0
  21. if spending_too_many_days:
  22.     print("You can't save the money.")
  23.     print(total_days)
  24. else:
  25.     print(f" You saved the money for {total_days} days.")
Advertisement
Add Comment
Please, Sign In to add comment