class HexagonInteriorAngle(object):
def __init__(self, x):
self.x = self
def FindInteriorAngle(self):
degrees = int((x - 2) * 180)
interior = int(degrees / x)
def Print(self):
if x == 3:
print(str("an interior angle of a triangle equals " + str(interior)))
elif x == 4:
print("an interior angle of an equilateral equals " + str(interior))
elif x == 5:
print("an interior angle of a pentagon equals " + str(interior))
elif x == 6:
print("an interior angle of a hexagon equals " + str(interior))
elif x == 7:
print("an interior angle of a heptagon equals " + str(interior))
elif x == 8:
print("an interior angle of an octagon equals " + str(interior))
elif x == 9:
print("an interior angle of a nonagon equals " + str(interior))
elif x == 10:
print("an interior angle of a decagon equals " + str(interior))
else:
print(str(interior))
if __name__ == "__main__":
x = int(input("enter: "))
hexaObj = HexagonInteriorAngle(x)
hexaObj.FindInteriorAngle()
hexaObj.Print()
what i want to program to do is identify what type of polygon it is based off of the number of sides (ex. 6 sides = hexagon, 5 sides = pentagon, etc) and then print what one interior angle would be for that polygon (formula to find the interior angle : (the number of sides - 2) x 180 and then taking that answer and then dividing it by the number of sides). example: hexagon. ( 6 - 2 ) x 180 = 720 720 / 6 = 120
right now i'm pretty sure the actual code part is correct because if you do this it prints fine:
class HexagonInteriorAngle(object):
def __init__(self, x):
self.x = self
def FindInteriorAngle(self):
degrees = int((x - 2) * 180)
interior = int(degrees / x)
print("interior angle " + str(interior))
if __name__ == "__main__":
x = int(input("enter: "))
hexaObj = HexagonInteriorAngle(x)
hexaObj.FindInteriorAngle()
Aucun commentaire:
Enregistrer un commentaire