desislava_topuzakova

03. Vacation

Apr 4th, 2021
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. # стоп: налични пари >= нужни пари
  2. # продължаваме: налични пари < нужни пари
  3. need_money = float(input()) # нужни пари
  4. current_money = float(input()) # налични пари
  5.  
  6. count_spend_days = 0 # брой на дни, в които харчим
  7. count_days = 0 # брой на дните, в които или харчим или пестим
  8.  
  9. while current_money < need_money:
  10.     # извършвам действие (spend/save)
  11.     action = input() # spend or save
  12.     count_days += 1
  13.     sum = float(input())
  14.     if action == "spend":
  15.         # харчи
  16.         count_spend_days += 1
  17.         current_money -= sum
  18.         if current_money < 0:
  19.             current_money = 0
  20.     elif action == "save":
  21.         # пести
  22.         count_spend_days = 0
  23.         current_money += sum
  24.     # проверка дали 5 последователни дни харчи
  25.     if count_spend_days == 5:
  26.         print("You can't save the money.")
  27.         print(count_days)
  28.         break
  29. else: # наличните пари >= нужните пари
  30.     print(f"You saved the money for {count_days} days.")
Advertisement
Add Comment
Please, Sign In to add comment