Advertisement
Spocoman

05. Small Shop

Dec 19th, 2021 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 KB | None | 0 0
  1. product = input()
  2. town = input()
  3. quantity = float(input())
  4. price = 0
  5.  
  6. if town == "Sofia":
  7.     if product == "coffee":
  8.         price = 0.5
  9.     elif product == "water":
  10.         price = 0.8
  11.     elif product == "beer":
  12.         price = 1.2
  13.     elif product == "sweets":
  14.         price = 1.45
  15.     elif product == "peanuts":
  16.         price = 1.6
  17.  
  18. elif town == "Plovdiv":
  19.     if product == "coffee":
  20.         price = 0.4
  21.     elif product == "water":
  22.         price = 0.7
  23.     elif product == "beer":
  24.         price = 1.15
  25.     elif product == "sweets":
  26.         price = 1.3
  27.     elif product == "peanuts":
  28.         price = 1.5
  29.  
  30. elif town == "Varna":
  31.     if product == "coffee":
  32.         price = 0.45
  33.     elif product == "water":
  34.         price = 0.7
  35.     elif product == "beer":
  36.         price = 1.1
  37.     elif product == "sweets":
  38.         price = 1.35
  39.     elif product == "peanuts":
  40.         price = 1.55
  41.  
  42. print(price * quantity)
  43.  
  44.  
  45. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  46.  
  47. product = input()
  48. town = input()
  49. quantity = float(input())
  50.  
  51. price = (0.5 if town == 'Sofia' else 0.4 if town == 'Plovdiv' else 0.45 if town == 'Varna' else 0) if product == 'coffee' else \
  52.         (0.8 if town == 'Sofia' else 0.7 if town == 'Plovdiv' else 0.7 if town == 'Varna' else 0) if product == 'water' else \
  53.         (1.2 if town == 'Sofia' else 1.15 if town == 'Plovdiv' else 1.1 if town == 'Varna' else 0) if product == 'beer' else \
  54.         (1.45 if town == 'Sofia' else 1.3 if town == 'Plovdiv' else 1.35 if town == 'Varna' else 0) if product == 'sweets' else \
  55.         (1.6 if town == 'Sofia' else 1.5 if town == 'Plovdiv' else 1.55 if town == 'Varna' else 0) if product == 'peanuts' else 0
  56.  
  57. print(price * quantity)
  58.  
  59.  
  60. РЕШЕНИЕ С РЕЧНИК:
  61.  
  62. product = input()
  63. town = input()
  64. quantity = float(input())
  65.  
  66. price = {'coffee': {'Sofia': 0.5, 'Plovdiv': 0.4, 'Varna': 0.45},
  67.          'water': {'Sofia': 0.8, 'Plovdiv': 0.7, 'Varna': 0.7},
  68.          'beer': {'Sofia': 1.2, 'Plovdiv': 1.15, 'Varna': 1.1},
  69.          'sweets': {'Sofia': 1.45, 'Plovdiv': 1.3, 'Varna': 1.35},
  70.          'peanuts': {'Sofia': 1.6, 'Plovdiv': 1.5, 'Varna': 1.55}
  71.          }[product][town]
  72.  
  73. print(price * quantity)
  74.  
  75.  
  76. Или тарикатската:)
  77.  
  78. print({'coffee': {'Sofia': 0.5, 'Plovdiv': 0.4, 'Varna': 0.45}, 'water': {'Sofia': 0.8, 'Plovdiv': 0.7, 'Varna': 0.7},
  79.        'beer': {'Sofia': 1.2, 'Plovdiv': 1.15, 'Varna': 1.1}, 'sweets': {'Sofia': 1.45, 'Plovdiv': 1.3, 'Varna': 1.35},
  80.        'peanuts': {'Sofia': 1.6, 'Plovdiv': 1.5, 'Varna': 1.55}}[input()][input()] * float(input()))
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement