Here's my code, it seems kind of repetitive, but I couldn't figure out a way to make it differently. Maybe someone here can help me? (It works okay btw, but it seems to me it's a bit "unclean")
while True:
try:
num1 = int(input("Type in the first parameter: "))
num2 = int(input("Type in the second parameter: "))
num3 = int(input("Type in the third parameter: "))
break
except ValueError:
print("You have to type in a number. ")
while True:
if num1 > num2 and num1 > num3:
c = num1
if c * c == num2 * num2 + num3 * num3:
print("Your triangle is a pythagorean triangle")
else:
print("Your triangle isn't a pythagorean triangle")
elif num2 > num1 and num2 > num3: # c - hypotenuse
c = num2
if c * c == num1 * num1 + num3 * num3:
print("Your triangle is a pythagorean triangle")
else:
print("Your triangle isn't a pythagorean triangle")
elif num3 > num1 and num3 > num2:
c = num3
if c * c == num2 * num2 + num1 * num1:
print("Your triangle is a pythagorean triangle")
else:
print("Your triangle isn't a pythagorean triangle")
elif num1 == num2 and num2 == num3 and num1 == num3:
print("There's no such thing as a pythagorean triangle with all sides the same, try again")
again = str(input("Do you want to continue? [Y/n]\n"))
if again == "Y" or again == "y":
pass
else:
break
I'm a little butterfly and I like flying around and my favorite flower is a dandelion because it's nice and yellow
Aucun commentaire:
Enregistrer un commentaire