19 AnswersNew Answer
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 PMZone
19 AnswersNew Answer
This should work. isRightAngle = side3**2 == (side1**2 + side2**2) print("Right-angled" if isRightAngle else "Not right-angled")
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")
Zone and what difference between side1*side1 and side1**side1?
Petr I guess that's a mistake, I don't need the **
Petr either way only 2 of 4 tests say it's correct
Petr the extra "*side1" isn't necessary I'm assuming?
Thanks for everyone who helped and tried to help ✊🏾
I messaged him directly for help.. for some reason I can't tag him in the discussion.
Zone is side1**side1 a square of side1? For example side1==25..
Zone ** is exponentiation, and * is multiplication
Zone ок. Then at first you did side1*=side1, then in if you write side1*side1. So i have side1**4. :)))
Zone Can you put your code in your profile?
Zone i just ask you. But you maybe right:)))
Petr ?? what do you mean? It's in the post already
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!
Ore your answer works too... 👍🏾
Ore since he wasn't in the discussion I marked your answer as best answer 👍🏾
Zone welcome. But I don't see any Steven M in this discussion.
Learn Playing. Play Learning
SoloLearn Inc.4 Embarcadero Center, Suite 1455
Send us a message