Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- flowers = input()
- volume = int(input())
- budget = int(input())
- price = 0
- if flowers == 'Roses':
- price = volume * 5
- if volume > 80:
- price *= 0.9
- elif flowers == 'Dahlias':
- price = volume * 3.8
- if volume > 90:
- price *= 0.85
- elif flowers == 'Tulips':
- price = volume * 2.8
- if volume > 80:
- price *= 0.85
- elif flowers == 'Narcissus':
- price = volume * 3
- if volume < 120:
- price *= 1.15
- elif flowers == 'Gladiolus':
- price = volume * 2.5
- if volume < 80:
- price *= 1.2
- if budget < price:
- print(f'Not enough money, you need {price - budget:.2f} leva more.')
- else:
- print(f'Hey, you have a great garden with {volume} {flowers} and {budget - price:.2f} leva left.')
- Решение с тернарен оператор:
- flowers = input()
- volume = int(input())
- budget = float(input())
- budget -= (5 * (0.9 if volume > 80 else 1) if flowers == "Roses" else
- 3.8 * (0.85 if volume > 90 else 1) if flowers == "Dahlias" else
- 2.8 * (0.85 if volume > 80 else 1) if flowers == "Tulips" else
- 3 * (1.15 if volume < 120 else 1) if flowers == "Narcissus" else
- 2.5 * (1.2 if volume < 80 else 1) if flowers == "Gladiolus" else 0) * volume
- print(f'Not enough money, you need {abs(budget):.2f} leva more.' if budget < 0 else
- f'Hey, you have a great garden with {volume} {flowers} and {budget:.2f} leva left.')
- Решение с колекция и тернарен оператор:
- flowers = input()
- volume = int(input())
- budget = float(input())
- budget -= {"Roses": 5 * (0.9 if volume > 80 else 1),
- "Dahlias": 3.8 * (0.85 if volume > 90 else 1),
- "Tulips": 2.8 * (0.85 if volume > 80 else 1),
- "Narcissus": 3 * (1.15 if volume < 120 else 1),
- "Gladiolus": 2.5 * (1.2 if volume < 80 else 1)}[flowers] * volume
- print(f'Not enough money, you need {abs(budget):.2f} leva more.' if budget < 0 else
- f'Hey, you have a great garden with {volume} {flowers} and {budget:.2f} leva left.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement