Advertisement
Spocoman

Metric Converter(Simple Conditions)

Oct 8th, 2023 (edited)
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. distance = float(input())
  2. input_metric = input()
  3. output_metric = input()
  4.  
  5. if input_metric == "m":
  6.     distance /= 1000
  7. elif input_metric == "cm":
  8.     distance /= 100000
  9. elif input_metric == "mm":
  10.     distance /= 1000000
  11. elif input_metric == "mi":
  12.     distance /= 0.621371192
  13. elif input_metric == "in":
  14.     distance /= 39370.0787
  15. elif input_metric == "ft":
  16.     distance /= 3280.8399
  17. elif input_metric == "yd":
  18.     distance /= 1093.6133
  19.  
  20. if output_metric == "m":
  21.     distance *= 1000
  22. elif output_metric == "cm":
  23.     distance *= 100000
  24. elif output_metric == "mm":
  25.     distance *= 1000000
  26. elif output_metric == "mi":
  27.     distance *= 0.621371192
  28. elif output_metric == "in":
  29.     distance *= 39370.0787
  30. elif output_metric == "ft":
  31.     distance *= 3280.8399
  32. elif output_metric == "yd":
  33.     distance *= 1093.6133
  34.  
  35. print(distance)
  36.  
  37. РЕШЕНИЕ С КОЛЕКЦИЯ:
  38.  
  39. metrics_to_km = {
  40.     "km": 1,
  41.     "m": 1000,
  42.     "cm": 100000,
  43.     "mm": 1000000,
  44.     "mi": 0.621371192,
  45.     "in": 39370.0787,
  46.     "ft": 3280.8399,
  47.     "yd": 1093.6133
  48. }
  49.  
  50. distance = float(input())
  51. input_metric = input()
  52. output_metric = input()
  53.  
  54. print(distance / metrics_to_km[input_metric] * metrics_to_km[output_metric])
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement