I'm trying to create a small piece of code that uses pythagoras' theorem to calculate the length of the hypotenuse of a triangle and the angle opposite the height. To do this, the user has to enter the length and width of the triangle. I want to define a function so that the whole thing can be called as part of a larger program. Here's the code:
def ex1() :
from math import sqrt, atan, degrees
print("""Hello, this is a program that will calculate the length of the
hypotenuse of a triangle given the width and height of the triangle.
It will also calculate the angle opposite the height and adjacent to the width.
""")
myWidth = float(input("Please input the width of the triangle: "))
myHeight = float(input("Please input the height of the triangle: "))
hyp = sqrt(((myWidth**2) + (myHeight**2)))
angle = degrees(atan(myHeight/myWidth))
print("\nThe length of the hypotenuse is " + "%.1f" % hyp + " units")
print("\nThe size of the angle opposite the height and \nadjacent to the width is " + "%.1f" % angle + " degrees to 1 decimal place")
input = input("Press enter to end the program\n")
Can anyone explain to me that when I call it, it throws this error at me:
UnboundLocalError: local variable 'input' referenced before assignment
Many Thanks in advance