Advertisement
anton_d

03.vacation

Jan 27th, 2022 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. money_needed = float(input())
  2. saved_money = float(input())
  3.  
  4. days = 0
  5. spend_days = 0
  6. amount = 0
  7.  
  8. while saved_money < money_needed and spend_days < 5:
  9.     command = input()
  10.     amount = float(input())
  11.     days += 1
  12.     if command == 'save':
  13.         saved_money += amount
  14.         spend_days = 0
  15.     if command == 'spend':
  16.         spend_days += 1
  17.         saved_money -= amount
  18.         if saved_money < 0:
  19.             saved_money = 0
  20.  
  21.     if saved_money >= money_needed:
  22.         print(f'You saved the money for {days} days.')
  23.         break
  24. else:
  25.     print(f'You can\'t save the money.\n{days}')
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement