Spocoman

08. Fuel Tank - Part 2

Dec 19th, 2021 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. fuel = input()
  2. liters = float(input())
  3. cart = input()
  4. liter_price = 0
  5.  
  6. if cart == 'Yes':
  7.     if fuel == 'Gas':
  8.         liter_price = 0.85
  9.     elif fuel == 'Diesel':
  10.         liter_price = 2.21
  11.     elif fuel == 'Gasoline':
  12.         liter_price = 2.04
  13. else:
  14.     if fuel == 'Gas':
  15.         liter_price = 0.93
  16.     elif fuel == 'Diesel':
  17.         liter_price = 2.33
  18.     elif fuel == 'Gasoline':
  19.         liter_price = 2.22
  20.  
  21. if 20 <= liters <= 25:
  22.     liter_price *= 0.92
  23. elif liters > 25:
  24.     liter_price *= 0.9
  25.  
  26. print(f'{liter_price * liters:.2f} lv.')
  27.  
  28.  
  29. РЕШЕНИЕ С IF ELSE И ТЕРНАРЕН ОПЕРАТОР:
  30.  
  31. fuel = input()
  32. liters = float(input())
  33. cart = input()
  34. liter_price = 0
  35.  
  36. if fuel == 'Gas':
  37.     liter_price = 0.85 if cart == 'Yes' else 0.93
  38. elif fuel == 'Diesel':
  39.     liter_price = 2.21 if cart == 'Yes' else 2.33
  40. elif fuel == 'Gasoline':
  41.     liter_price = 2.04 if cart == 'Yes' else 2.22
  42.  
  43. liter_price *= 0.92 if 20 <= liters <= 25 else 0.9 if liters > 25 else 1
  44.  
  45. print(f'{liter_price * liters:.2f} lv.')
  46.  
  47.  
  48. И САМО С ТЕРНАРЕН ОПЕРАТОР:
  49.  
  50. fuel = input()
  51. liters = float(input())
  52. cart = input()
  53.  
  54. liter_price = (((0.85 if cart == 'Yes' else 0.93) if fuel == 'Gas' else
  55.                 (2.21 if cart == 'Yes' else 2.33) if fuel == 'Diesel' else
  56.                 (2.04 if cart == 'Yes' else 2.22) if fuel == 'Gasoline' else 0)
  57.                * (0.92 if 20 <= liters <= 25 else 0.9 if liters > 25 else 1))
  58.  
  59. print(f'{liter_price * liters:.2f} lv.')
  60.  
  61.  
  62. РЕШЕНИЕ С КОЛЕКЦИЯ И ТЕРНАРЕН ОПЕРАТОР:
  63.  
  64. fuel = input()
  65. liters = float(input())
  66. cart = input()
  67.  
  68. info = {'Gas': {'Yes': 0.85, 'No': 0.93},
  69.         'Diesel': {'Yes': 2.21, 'No': 2.33},
  70.         'Gasoline': {'Yes': 2.04, 'No': 2.22}}
  71.  
  72. liter_price = info[fuel][cart] * (0.92 if 20 <= liters <= 25 else 0.9 if liters > 25 else 1)
  73.  
  74. print(f'{liter_price * liters:.2f} lv.')
  75.  
Add Comment
Please, Sign In to add comment