Advertisement
Spocoman

04. Toy Shop

Dec 16th, 2021 (edited)
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. amount = float(input())
  2. puzzles = int(input())
  3. dolls = int(input())
  4. bears = int(input())
  5. minions = int(input())
  6. trucks = int(input())
  7.  
  8. puzzles_price = puzzles * 2.6
  9. dolls_price = dolls * 3
  10. bears_price = bears * 4.1
  11. minions_price = minions * 8.2
  12. trucks_price = trucks * 2
  13.  
  14. toys = puzzles + dolls + bears + minions + trucks
  15. price = puzzles_price + dolls_price + bears_price + minions_price + trucks_price
  16.  
  17. if toys >= 50:
  18.     price *= 0.75
  19.  
  20. price *= 0.9
  21.  
  22. if price >= amount:
  23.     print(f'Yes! {price - amount:.2f} lv left.')
  24. else:
  25.     print(f'Not enough money! {amount - price:.2f} lv needed.')
  26.  
  27.  
  28. Решение с колекция:
  29.  
  30. amount = float(input())
  31.  
  32. toy_count = {
  33.     'puzzles': int(input()),
  34.     'dolls': int(input()),
  35.     'bears': int(input()),
  36.     'minions': int(input()),
  37.     'trucks': int(input())
  38. }
  39.  
  40. toy_price = {
  41.     'puzzles': 2.60,
  42.     'dolls': 3.00,
  43.     'bears': 4.10,
  44.     'minions': 8.20,
  45.     'trucks': 2.00
  46. }
  47.  
  48. total_count = sum(toy_count.values())
  49. total_price = 0
  50.  
  51. for i in toy_price:
  52.     total_price += toy_price[i] * toy_count[i]
  53.    
  54. total_price *= 0.75 if total_count >= 50 else 1
  55. diff = total_price * 0.9 - amount
  56.  
  57. print(f'Yes! {diff:.2f} lv left.' if diff >= 0 else f'Not enough money! {abs(diff):.2f} lv needed.')
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement