Advertisement
Spocoman

11. Fruit Shop

Dec 20th, 2021 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.56 KB | None | 0 0
  1. fruit = input()
  2. day = input()
  3. quantity = float(input())
  4. price = 0
  5.  
  6. if day == "Monday" or day == "Tuesday" or day == "Wednesday" or day == "Thursday" or day == "Friday":
  7.     if fruit == "banana":
  8.         price = 2.5
  9.     elif fruit == "apple":
  10.         price = 1.2
  11.     elif fruit == "orange":
  12.         price = 0.85
  13.     elif fruit == "grapefruit":
  14.         price = 1.45
  15.     elif fruit == "kiwi":
  16.         price = 2.7
  17.     elif fruit == "pineapple":
  18.         price = 5.5
  19.     elif fruit == "grapes":
  20.         price = 3.85
  21.    
  22. elif day == "Saturday" or day == "Sunday":
  23.     if fruit == "banana":
  24.         price = 2.7
  25.     elif fruit == "apple":
  26.         price = 1.25
  27.     elif fruit == "orange":
  28.         price = 0.9
  29.     elif fruit == "grapefruit":
  30.         price = 1.6
  31.     elif fruit == "kiwi":
  32.         price = 3
  33.     elif fruit == "pineapple":
  34.         price = 5.6
  35.     elif fruit == "grapes":
  36.         price = 4.2
  37.  
  38. if price > 0:
  39.     print(f'{price * quantity:.2f}')
  40. else:
  41.     print("error")
  42.  
  43.  
  44. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  45.  
  46. fruit = input()
  47. day = input()
  48. quantity = float(input())
  49. price = 0
  50.  
  51. if day in ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"):
  52.     price = 2.5 if fruit == "banana" \
  53.         else 1.2 if fruit == "apple" \
  54.         else 0.85 if fruit == "orange" \
  55.         else 1.45 if fruit == "grapefruit" \
  56.         else 2.7 if fruit == "kiwi" \
  57.         else 5.5 if fruit == "pineapple" \
  58.         else 3.85 if fruit == "grapes" else 0
  59.  
  60. elif day in ("Saturday", "Sunday"):
  61.     price = 2.7 if fruit == "banana" \
  62.         else 1.25 if fruit == "apple" \
  63.         else 0.9 if fruit == "orange" \
  64.         else 1.6 if fruit == "grapefruit" \
  65.         else 3 if fruit == "kiwi" \
  66.         else 5.6 if fruit == "pineapple" \
  67.         else 4.2 if fruit == "grapes" else 0
  68.    
  69. print(f'{price * quantity:.2f}' if price > 0 else 'error')
  70.  
  71.  
  72.  
  73. РЕШЕНИЕ С КОЛЕКЦИЯ И ТЕРНАРЕН ОПЕРАТОР:
  74.  
  75. fruit = input()
  76. day = input()
  77. quantity = float(input())
  78.  
  79. workday_price = {'banana': 2.5, 'apple': 1.2, 'orange': 0.85, 'grapefruit': 1.45, 'kiwi': 2.7, 'pineapple': 5.5, 'grapes': 3.85}
  80. weekend_price = {'banana': 2.7, 'apple': 1.25, 'orange': 0.9, 'grapefruit': 1.6, 'kiwi': 3, 'pineapple': 5.6, 'grapes': 4.2}
  81.  
  82. price = 0
  83.  
  84. if day in ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday') and fruit in workday_price:
  85.     price = workday_price[fruit]
  86. elif day in ('Saturday', 'Sunday') and fruit in weekend_price:
  87.     price = weekend_price[fruit]
  88.    
  89. print(f'{price * quantity:.2f}' if price > 0 else 'error')
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement