Advertisement
Spocoman

03. Vacation

Dec 27th, 2021 (edited)
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. money_needed = float(input())
  2. budget = float(input())
  3. spend_days = 0
  4. save_days = 0
  5.  
  6. while budget < money_needed and spend_days < 5:
  7.     command = input()
  8.     money = float(input())
  9.     if command == 'spend':
  10.         spend_days += 1
  11.         if money >= budget:
  12.             budget = 0
  13.         else:
  14.             budget -= money
  15.     else:
  16.         budget += money
  17.         spend_days = 0
  18.     save_days += 1
  19.  
  20. if budget < money_needed:
  21.     print(f'You can\'t save the money.\n{save_days}')
  22. else:
  23.     print(f'You saved the money for {save_days} days.')
  24.    
  25.  
  26. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  27.  
  28. money_needed = float(input())
  29. budget = float(input())
  30. spend_days = 0
  31. save_days = 0
  32.  
  33. while budget < money_needed and spend_days < 5:
  34.     command = input()
  35.     money = float(input())
  36.     spend_days += 1 if command == 'spend' else -spend_days
  37.     budget -= (budget if money >= budget else money) if command == 'spend' else -money
  38.     save_days += 1
  39.  
  40. print(f'You saved the money for {save_days} days.' if budget >= money_needed else f'You can\'t save the money.\n{save_days}')
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement