Advertisement
Spocoman

06. Truck Driver

Dec 22nd, 2021 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. season = input()
  2. km = float(input())
  3. sum = 0
  4.  
  5. if 0 < km <= 5000:
  6.     if season == 'Spring' or season == 'Autumn':
  7.         sum = 0.75
  8.     elif season == 'Summer':
  9.         sum = 0.9
  10.     else:
  11.         sum = 1.05
  12. elif 5000 < km <= 10000:
  13.     if season == 'Spring' or season == 'Autumn':
  14.         sum = 0.95
  15.     elif season == 'Summer':
  16.         sum = 1.1
  17.     else:
  18.         sum = 1.25
  19. elif 10000 < km <= 20000:
  20.     sum = 1.45
  21.  
  22. print(f'{(sum * km * 4 * 0.9):.2f}')
  23.  
  24.  
  25. Решение с тернарен оператор:
  26.  
  27. season = input()
  28. km = float(input())
  29. sum = 0
  30.  
  31. if 0 < km <= 5000:
  32.     sum = 0.75 if season == 'Spring' or season == 'Autumn' else 0.9 if season == 'Summer' else 1.05
  33. elif 5000 < km <= 10000:
  34.     sum = 0.95 if season == 'Spring' or season == 'Autumn' else 1.1 if season == 'Summer' else 1.25    
  35. elif 10000 < km <= 20000:
  36.     sum = 1.45
  37.  
  38. print(f'{(sum * km * 4 * 0.9):.2f}')
  39.  
  40.  
  41. Решение с колекция:
  42.  
  43. season = input()
  44. km = float(input())
  45.  
  46. budget = {0 < km <= 5000: {"Spring": 0.75, "Autumn": 0.75, "Summer": 0.9, "Winter": 1.05},
  47.           5000 < km <= 10000: {"Spring": 0.95, "Autumn": 0.95, "Summer": 1.1, "Winter": 1.25},
  48.           km > 10000: {"Spring": 1.45, "Autumn": 1.45, "Summer": 1.45, "Winter": 1.45}}
  49.  
  50. print(f"{(budget[True][season] * km * 4 * 0.9):.2f}")
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement