sibinasto

10.03. Vacation

Dec 2nd, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 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.     sums = float(input())
  9.     total_days += 1
  10.     if action == 'spend':
  11.         money_in_hand -= sums
  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.         continue
  19.     else:
  20.         money_in_hand += sums
  21.         spending_days_counter = 0
  22. if spending_too_many_days:
  23.     print("You can't save the money.")
  24.     print(total_days)
  25. else:
  26.     print(f"You saved the money for {total_days} days.")
Advertisement
Add Comment
Please, Sign In to add comment