0
What am I doing wrong?
side1 = int(input()) side2 = int(input()) side3 = int(input()) sot = "side1 + side2" if sot == side3: print("Right-angled") else: print("Not right-angled") This is for the right angle programme.
5 Respostas
+ 11
Alex I think you're trying to do something like this
side1 = int(input())
side2 = int(input())
side3 = int(input())
if side1**2 == side2**2 + side3**2:
print("Right-angled")
else:
print("Not right-angled")
+ 6
Why sot="side1 +side2".
You dont need ""
+ 6
All codes shown here do not give a correct answer in all cases. The correct way is to check if the square of the LONGEST side (hypotenuse) is equal to the sum of the squares of the other 2 sides. As you can not be sure about the sequence of the input, we have to check all possible combinations of the formula. If one of them is True, the triangle is right-angle. An other way could to find the longest side of all inputs, and do the calculation from this base.
inp = sorted([int(i)**2 for i in input('3 nums sep. by space :').split()])
if inp[-1] == inp[0] + inp[1]:
print('right-angle')
else:
print('NOT right-angle')
+ 1
Lose the quotes when you assign the sot variable, it should be:
sot = side1 + side2
and i think the formula is a^2 + b^2 = c^2
+ 1
thank you :)