Advertisement
Spocoman

Metric Converter

Feb 24th, 2022 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. number = float(input())
  2. inputMetric = input()
  3. outputMetric = input()
  4.  
  5. if inputMetric == "mm":
  6.     if outputMetric == "cm":
  7.         number /= 10
  8.     else:
  9.         number /= 1000
  10. elif inputMetric == "cm":
  11.     if outputMetric == "m":
  12.         number /= 100
  13.     else:
  14.         number *= 10
  15. else:
  16.     if outputMetric == "cm":
  17.         number *= 100
  18.     else:
  19.         number *= 1000
  20.        
  21. print(f"{number:.3f}")
  22.  
  23.  
  24. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  25.  
  26. number = float(input())
  27. inputMetric = input()
  28. outputMetric = input()
  29.  
  30. if inputMetric == "mm":
  31.     number /= 10 if outputMetric == "cm" else 1000
  32. elif inputMetric == "cm":
  33.     number *= 0.01 if outputMetric == "m" else 10
  34. else:
  35.     number *= 100 if outputMetric == "cm" else 1000
  36.  
  37. print(f"{number:.3f}")
  38.  
  39.  
  40. ИЛИ:
  41.  
  42. number = float(input())
  43. inputMetric = input()
  44. outputMetric = input()
  45.  
  46. number *= ((0.1 if outputMetric == "cm" else 0.001) if inputMetric == "mm" else
  47.            (0.01 if outputMetric == "m" else 10) if inputMetric == "cm" else
  48.            (100 if outputMetric == "cm" else 1000))
  49.  
  50. print(f"{number:.3f}")
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement