Pythagoras theorem / Else Statements (Python) | SoloLearn: Learn to code for FREE!

+1

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..

9/22/2020 9:44:00 PM

Zone

19 Answers

New Answer

+2

This should work. isRightAngle = side3**2 == (side1**2 + side2**2) print("Right-angled" if isRightAngle else "Not right-angled")

+3

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")

+1

Zone and what difference between side1*side1 and side1**side1?

+1

Petr I guess that's a mistake, I don't need the **

+1

Petr either way only 2 of 4 tests say it's correct

+1

Petr the extra "*side1" isn't necessary I'm assuming?

+1

Thanks for everyone who helped and tried to help ✊🏾

+1

I messaged him directly for help.. for some reason I can't tag him in the discussion.

0

Zone is side1**side1 a square of side1? For example side1==25..

0

Petr yes

0

Zone ** is exponentiation, and * is multiplication

0

Zone ок. Then at first you did side1*=side1, then in if you write side1*side1. So i have side1**4. :)))

0

Zone Can you put your code in your profile?

0

Zone i just ask you. But you maybe right:)))

0

Petr ?? what do you mean? It's in the post already

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!

0

Ore your answer works too... 👍🏾

0

Ore since he wasn't in the discussion I marked your answer as best answer 👍🏾

-1

Zone welcome. But I don't see any Steven M in this discussion.