Advertisement
c0d3dsk1lls

Useful Python math functions CodedSkills.net

Aug 3rd, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. #============================================================================================================
  2. #Useful Python math functions
  3. #-------------------------------------------------------------
  4. import math
  5. pi = 3.14
  6. print(round(pi)) #ROUNDS TO NEAREST WHOLE INTEGER
  7.  
  8. #-------------------------------------------------------------
  9. import math
  10. pi = 3.14
  11. print(math.ceil(pi)) #ROUND A NUMBER UP TO NEAREST INTEGER
  12. #-------------------------------------------------------------
  13. import math
  14. pi = 3.14
  15. print(math.floor(pi)) #ROUND A NUMBER DOWN TO NEAREST INTEGER
  16. #-------------------------------------------------------------
  17. import math
  18. pi = -3.14
  19. print(abs(pi)) #GIVES THE ABSOLUTE VALUE OF A NUMBER
  20. #-------------------------------------------------------------
  21. import math
  22. pi = -3.14
  23. print(pow(pi,2)) #RAISE BASE NUMBER TO THE POWER OF 2
  24. #-------------------------------------------------------------
  25. import math
  26. pi = 3.14
  27. print(math.sqrt(420)) #SQUARE ROOT FUNCTION
  28. #-------------------------------------------------------------
  29. import math
  30. pi = 3.14
  31. X = 1
  32. Y = 2
  33. Z = 3
  34. print(max(X,Y,Z)) #FINDS THE LARGEST VALUE BETWEEN X, Y, & Z
  35. #-------------------------------------------------------------
  36. import math
  37. pi = 3.14
  38. X = 1
  39. Y = 2
  40. Z = 3
  41. print(min(X,Y,Z)) #FINDS THE LOWEST VALUE BETWEEN X, Y, & Z
  42. #-------------------------------------------------------------
  43. #============================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement