Advertisement
Antyos

Pythagorean Theorem Calculator

Apr 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. # Pythogrean Theorem calculator in Python 3
  2. # Usage in command line: python pythagorean.py <num1> <num2> <num3> ...
  3.  
  4. import sys
  5. from math import sqrt
  6.  
  7. args = sys.argv[1:]
  8. numbers = []
  9.  
  10. for num in args:
  11.     numbers.append(float(num) ** 2)
  12.  
  13. pyt  = sqrt(sum(numbers))
  14.  
  15. print("{:.3f}".format(pyt))
  16.  
  17.  
  18.  
  19. # Batch file:
  20. #  To type "pyt <num1> <num2> <num3> ..." instead of the longer version:
  21. #  Place file "pyt.bat" (or any short name) in PATH or "C:\Users\<Current User>\"
  22. #      python "<Path>\pythagorean.py" %*
  23. #
  24. #      Note: Replace <Path> with the path of this file
  25. #            pythagorean.py should be the name of the Python script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement