Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import time
  2. import math
  3.  
  4.  
  5. def hypcalc():
  6. print("\nThis calculates the hypotenuse of a right-angled triangle")
  7. time.sleep(0.5)
  8. print("\nEnter one of the sides (cm)")
  9. side1 = float(input())
  10. print("\nEnter the other side (cm)")
  11. side2 = float(input())
  12.  
  13. side1sqrd = math.pow(side1, 2)
  14.  
  15. side2sqrd = math.pow(side2, 2)
  16.  
  17. hypsqrd = (side1sqrd + side2sqrd)
  18.  
  19. hyp = math.sqrt(hypsqrd)
  20.  
  21. print("\nThe hypotenuse is " + str(float(hyp)) + " cm")
  22.  
  23.  
  24.  
  25. def rightangled():
  26. print("This figures out if the triangle is right-angled based on the numbers entered")
  27. time.sleep(0.5)
  28. print("\nPlease enter one of the sides (cm)")
  29. side1 = float(input())
  30.  
  31. print("\nPlease enter another side (cm)")
  32. side2 = float(input())
  33.  
  34. print("\nPlease enter the final side (cm)")
  35. side3 = float(input())
  36.  
  37. sides = [side1, side2, side3]
  38. sides.sort()
  39.  
  40. hyp = sides[2]
  41.  
  42. hypsqrd = (hyp * hyp)
  43.  
  44. short = sides[0]
  45. long = sides[1]
  46.  
  47. shortsqrd = (short * short)
  48. longsqrd = (long * long)
  49.  
  50. ans = (shortsqrd + longsqrd)
  51.  
  52.  
  53. if hypsqrd == ans:
  54. print("This is a right-angled triangle")
  55.  
  56. else:
  57. print("This is not a right-angled triangle")
  58.  
  59.  
  60.  
  61. def spareside():
  62. print("This calculated the missing side of a triangle")
  63. time.sleep(0.5)
  64. print("\nPlease enter the hypotenuse (cm)")
  65. side1 = int(input())
  66. print("\nPlease enter the other side (cm)")
  67. side2 = int(input())
  68.  
  69. sides = [side1, side2]
  70. sides.sort()
  71.  
  72. hyp = sides[1]
  73. other = sides[0]
  74.  
  75. hypsqrd = math.pow(hyp, 2)
  76. othersqrd = math.pow(other, 2)
  77.  
  78. sparesqrd = (hypsqrd - othersqrd)
  79.  
  80. spare = math.sqrt(sparesqrd)
  81.  
  82. print("\nThe spare side is " + str(float(spare)) + " cm")
  83.  
  84.  
  85. def menu():
  86.  
  87. def choosing():
  88.  
  89. print("What would you like to run?")
  90. print("---------------------------------")
  91. print("| 1. Hypotenuse calculator |")
  92. print("| 2. Right-angle verifier |")
  93. print("| 3. Remaining side calculator |")
  94. print("---------------------------------\n")
  95.  
  96. global choice
  97. choice = input()
  98.  
  99.  
  100. if choice == "1":
  101. hypcalc()
  102.  
  103. elif choice == "2":
  104. rightangled()
  105.  
  106. elif choice == "3":
  107. spareside()
  108.  
  109. choicelist = ["1", "2", "3"]
  110. while choice not in choicelist:
  111.  
  112.  
  113. choosing()
  114.  
  115.  
  116. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement