Can someone please tell me what is the mistake in the code given in description , the output is also given | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone please tell me what is the mistake in the code given in description , the output is also given

num1 = int(input("Enter number 1")) num2 = int(input("Enter number 2")) num3 = int(input("Enter number 3")) if num1**2 == num2**2 + num3**2 : print("(str(num1),str(num2),str(num3)) are Pythagorean triplets") else : if num2**2 == num1**2 + num3**2 : print("(str(num1),str(num2),str(num3)) are Pythagorean triplets") else : if num3**2 == num1**2 + num2**2 : print("(str(num1),str(num2),str(num3)) are Pythagorean triplets") else : print("(str(num1),str(num2),str(num3)) are not Pythagorean triplets") Output :- File "source_file.py", line 7 else : ^ SyntaxError: invalid syntax Process finished with exit code 1.

18th Jan 2021, 11:53 AM
Tanishq Kamble
Tanishq Kamble - avatar
2 Answers
+ 3
Indentation is not proper. You can use "else if" in python like this "elif". num1 = int(input("Enter number 1\n")) num2 = int(input("Enter number 2\n")) num3 = int(input("Enter number 3\n")) if num1**2 == num2**2 + num3**2: print("(", num1, ",", num2, ",", num3, ") are Pythagorean triplets") elif num2**2 == num1**2 + num3**2: print("(", num1, ",", num2, ",", num3, ") are Pythagorean triplets") elif num3**2 == num1**2 + num2**2: print("(", num1, ",", num2, ",", num3, ") are Pythagorean triplets") else: print("(", num1, ",", num2, ",", num3, ") are not Pythagorean triplets")
18th Jan 2021, 12:25 PM
Rohit
0
?
18th Jan 2021, 11:53 AM
Tanishq Kamble
Tanishq Kamble - avatar