+ 1

Im stuck with Python

Im stuck with this, I have tried this many times but hidden requirement number 3 isnt satisfied, Need help. Pythagoras theorem says: In a right-angled triangle, the square of the hypotenuse side is equal to the sum of squares of the other two sides. Write a program that takes lengths of triangle sides as inputs, and output whether our triangle is right-angled or not. If the triangle is right-angled, the program should output "Right-angled", and "Not right-angled" if it's not. Sample Input 3 4 7 Sample Output Not right-angled My code: side1 = int(input()) side2 = int(input()) side3 = int(input()) #your code goes here if side1 + side2 <= side3: print("Not right-angled") if side1 + side2 > side3: print("Right-angled")

23rd Dec 2020, 12:36 PM
Andreas Kase
Andreas Kase - avatar
4 Respostas
+ 2
Read the theorem again. "The SQUARE of the hypotenuse is equal to the sum of SQUARES of the other 2 sides". You have not sqaured anything in the code. Also, the if conditions `if side1 + side2 > side3:` means that `if the sum of side1 and side2 is GREATER THAN side3`. You don't want greater than, you want equal to.
23rd Dec 2020, 12:41 PM
XXX
XXX - avatar
0
Thx, I got it finally
23rd Dec 2020, 12:55 PM
Andreas Kase
Andreas Kase - avatar
0
Side1 = int(input()) Side2 = int(input()) Side3 = int(input()) If C = sqrt(side1**2 + side2**2): Print("right angled") Else: Print ("not right angled")
11th Aug 2021, 2:29 AM
Harisha.L
0
##checks if we can use pythagoras theorem on a triangle a = float(input("Enter length of side a: ")) b = float(input("Enter length of side b: ")) c = float(input("Enter lentth of side c: ")) if (a**2) == (b**2) + (c**2): print("This is a right-angled triangle. Use Pythagoras Theorem!") else: if (b**2) == (a**2) + (c**2): print("This is a right angled-triangle. Use Pythagoras Theorem!") else: if (c**2) == (b**2) + (a**2): print("This is a right-angled triangle. Use Pythagoras Theorem!") else: print("Not a right-angled triangle. Pythagoras Theorem is not applicable.")
12th Feb 2022, 5:00 PM
Matumbai Binale
Matumbai Binale - avatar