0

Pythagoras theorem / Else Statements (Python)

Else Statement 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 [Take the 3rd input (side3 variable in sample code) as the longest side, which will represent the hypotenuse if the triangle is right-angled.] ________ My solution: side1 = int(input()) side2 = int(input()) side3 = int(input()) #your code goes here side1 *= side1 side2 *= side2 side3 *= (side1 * side1) + (side2 * side2) if side3 <= (side1*side1) + (side2*side2):     print("Right-angled") else:     print ("Not right-angled") __________ My solution works for 2 tests, but not the other 2..

22nd Sep 2020, 9:44 PM
Zone
Zone - avatar
27 odpowiedzi
- 1
This should work. isRightAngle = side3**2 == (side1**2 + side2**2) print("Right-angled" if isRightAngle else "Not right-angled")
22nd Sep 2020, 10:33 PM
Ore
Ore - avatar
+ 10
I received the answer courtesy of @Steven M side1 = int(input()) side2 = int(input()) side3 = int(input()) #your code goes here if (side1**2) + (side2**2) == side3**2: print("Right-angled") else: print("Not right-angled")
22nd Sep 2020, 10:53 PM
Zone
Zone - avatar
+ 3
Zone and what difference between side1*side1 and side1**side1?
22nd Sep 2020, 9:49 PM
Petr
+ 1
Petr either way only 2 of 4 tests say it's correct
22nd Sep 2020, 9:52 PM
Zone
Zone - avatar
+ 1
Petr the extra "*side1" isn't necessary I'm assuming?
22nd Sep 2020, 9:54 PM
Zone
Zone - avatar
+ 1
Thanks for everyone who helped and tried to help ✊🏾
22nd Sep 2020, 10:54 PM
Zone
Zone - avatar
+ 1
I messaged him directly for help.. for some reason I can't tag him in the discussion.
22nd Sep 2020, 11:00 PM
Zone
Zone - avatar
+ 1
side1 = int(input()) side2 = int(input()) side3 = int(input()) if (side1 **2) + (side2 **2) == (side3 **2): print("Right-angled") else: print( "Not right-angled") My solution works for 4 tests
28th Dec 2020, 12:46 AM
cristiano grandi
cristiano grandi - avatar
+ 1
if side1**2 + side2**2 == side3**2: print("Right-angled") else: print("Not right-angled")
14th Sep 2021, 11:40 PM
Kevin
0
Zone is side1**side1 a square of side1? For example side1==25..
22nd Sep 2020, 9:47 PM
Petr
0
Petr yes
22nd Sep 2020, 9:48 PM
Zone
Zone - avatar
0
Petr I guess that's a mistake, I don't need the **
22nd Sep 2020, 9:50 PM
Zone
Zone - avatar
0
Zone ** is exponentiation, and * is multiplication
22nd Sep 2020, 9:51 PM
Petr
0
Zone ок. Then at first you did side1*=side1, then in if you write side1*side1. So i have side1**4. :)))
22nd Sep 2020, 9:53 PM
Petr
0
Zone Can you put your code in your profile?
22nd Sep 2020, 9:54 PM
Petr
0
Zone i just ask you. But you maybe right:)))
22nd Sep 2020, 9:55 PM
Petr
0
Petr ?? what do you mean? It's in the post already
22nd Sep 2020, 9:56 PM
Zone
Zone - avatar
0
Isn't the question asking this =>, if side3*side3==side1*side1+side2*side2: right angled Else Not right angled I am trying to understand what is side3*=(side1*side1)+... doing Also why <=? according to the last calculation of yours ,side3 has the largest value now ,so <= will never work lol!
22nd Sep 2020, 10:06 PM
Abhay
Abhay - avatar
0
Ore your answer works too... 👍🏾
22nd Sep 2020, 10:55 PM
Zone
Zone - avatar
0
Ore since he wasn't in the discussion I marked your answer as best answer 👍🏾
22nd Sep 2020, 11:12 PM
Zone
Zone - avatar