Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- money_needed = float(input())
- budget = float(input())
- spend_days = 0
- save_days = 0
- while budget < money_needed and spend_days < 5:
- command = input()
- money = float(input())
- if command == 'spend':
- spend_days += 1
- if money >= budget:
- budget = 0
- else:
- budget -= money
- else:
- budget += money
- spend_days = 0
- save_days += 1
- if budget < money_needed:
- print(f'You can\'t save the money.\n{save_days}')
- else:
- print(f'You saved the money for {save_days} days.')
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- money_needed = float(input())
- budget = float(input())
- spend_days = 0
- save_days = 0
- while budget < money_needed and spend_days < 5:
- command = input()
- money = float(input())
- spend_days += 1 if command == 'spend' else -spend_days
- budget -= (budget if money >= budget else money) if command == 'spend' else -money
- save_days += 1
- 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}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement