Advertisement
Spocoman

03. New House

Dec 20th, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. flowers = input()
  2. volume = int(input())
  3. budget = int(input())
  4. price = 0
  5.  
  6. if flowers == 'Roses':
  7.     price = volume * 5
  8.     if volume > 80:
  9.         price *= 0.9
  10. elif flowers == 'Dahlias':
  11.     price = volume * 3.8
  12.     if volume > 90:
  13.         price *= 0.85
  14. elif flowers == 'Tulips':
  15.     price = volume * 2.8
  16.     if volume > 80:
  17.         price *= 0.85
  18. elif flowers == 'Narcissus':
  19.     price = volume * 3
  20.     if volume < 120:
  21.         price *= 1.15
  22. elif flowers == 'Gladiolus':
  23.     price = volume * 2.5
  24.     if volume < 80:
  25.         price *= 1.2
  26.  
  27. if budget < price:
  28.    print(f'Not enough money, you need {price - budget:.2f} leva more.')
  29. else:
  30.     print(f'Hey, you have a great garden with {volume} {flowers} and {budget - price:.2f} leva left.')
  31.  
  32. Решение с тернарен оператор:
  33.  
  34. flowers = input()
  35. volume = int(input())
  36. budget = float(input())
  37.  
  38. budget -= (5 * (0.9 if volume > 80 else 1) if flowers == "Roses" else
  39.            3.8 * (0.85 if volume > 90 else 1) if flowers == "Dahlias" else
  40.            2.8 * (0.85 if volume > 80 else 1) if flowers == "Tulips" else
  41.            3 * (1.15 if volume < 120 else 1) if flowers == "Narcissus" else
  42.            2.5 * (1.2 if volume < 80 else 1) if flowers == "Gladiolus" else 0) * volume
  43.  
  44. print(f'Not enough money, you need {abs(budget):.2f} leva more.' if budget < 0 else
  45.       f'Hey, you have a great garden with {volume} {flowers} and {budget:.2f} leva left.')
  46.  
  47. Решение с колекция и тернарен оператор:
  48.  
  49. flowers = input()
  50. volume = int(input())
  51. budget = float(input())
  52.  
  53. budget -= {"Roses": 5 * (0.9 if volume > 80 else 1),
  54.            "Dahlias": 3.8 * (0.85 if volume > 90 else 1),
  55.            "Tulips": 2.8 * (0.85 if volume > 80 else 1),
  56.            "Narcissus": 3 * (1.15 if volume < 120 else 1),
  57.            "Gladiolus": 2.5 * (1.2 if volume < 80 else 1)}[flowers] * volume
  58.  
  59. print(f'Not enough money, you need {abs(budget):.2f} leva more.' if budget < 0 else
  60.       f'Hey, you have a great garden with {volume} {flowers} and {budget:.2f} leva left.')
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement