0

Help me fix the python code below

def hypotenuse(leg1, leg2): #our function takes two arguments the leg 1 and leg 2 return( leg1**2 +leg 2**2)**(1/2) #according to the pythagorus theorem hypotenuse is equal to the square root of the sum of the squared legs print ("Test number 1, triangle with legs 3 and 4, hypotenuse is:," hypotenuse(3,4) ) #prints the call for triangle with legs 3 and 4 print ("Test number 2, triangle with legs 8 and 9, hypotenuse is:," + hypotenuse(8,9) ) #prints the call for triangle with legs 8 and 9 print ("Test number 3, triangle with legs 12 and 15, hypotenuse is:," + hypotenuse(12,15) )

15th Dec 2021, 10:43 AM
Tyga Sparta
2 Respuestas
+ 2
Your function returns a float value and it cannt be added in string using + operator in python ( other language supports it ) so remove + and use "," over there
15th Dec 2021, 10:58 AM
Ayush Kumar
Ayush Kumar - avatar
+ 2
Besides 丹ⓨㄩک廾's answer, also remove the spurious space from +leg 2**2.
15th Dec 2021, 10:35 PM
Brian
Brian - avatar