Advertisement
veronikaaa86

03. Vacation

Jul 30th, 2023
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. needed_money = float(input())
  2. init_money = float(input())
  3.  
  4. count_spend_days = 0
  5. count_total_days = 0
  6. total_sum = init_money
  7. while total_sum < needed_money:
  8.     if count_spend_days == 5:
  9.         break
  10.  
  11.     action = input()
  12.     amount = float(input())
  13.  
  14.     count_total_days += 1
  15.  
  16.     if action == "spend":
  17.         count_spend_days += 1
  18.         total_sum = total_sum - amount
  19.         if total_sum < 0:
  20.             total_sum = 0
  21.     else:
  22.         count_spend_days = 0
  23.         total_sum = total_sum + amount
  24.  
  25. if count_spend_days == 5:
  26.     print("You can't save the money.")
  27.     print(count_total_days)
  28. else:
  29.     print(f"You saved the money for {count_total_days} days.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement