[Tutor] Print result of function doesn't work
Torbjorn Svensson Diaz
torbjorn_svensson_diaz at yahoo.com
Mon Jul 22 07:21:35 EDT 2024
On 7/20/24 6:20 PM, Torbjorn Svensson Diaz via Tutor wrote:
> Hello, dear tutors!
>
Hello, dear tutors!
I've made it! Wohoo!
The following works.
import math
print("What is the length of the first leg of the triangle?")
leg1 = float(input())
print("What is the length of the second leg of the triangle?")
leg2 = float(input())
def hypotenuse(leg1, leg2):
legs = leg1**2 + leg2**2
result = math.sqrt(legs)
return result
x = hypotenuse(leg1, leg2)
print(x)
It turns out I had to convert the input into a float as it's a string by
default. Thanks for all your advice and guidance!
More information about the Tutor
mailing list