[Tutor] Print result of function doesn't work
dn
PythonList at DancesWithMice.info
Sun Jul 21 04:28:34 EDT 2024
On 21/07/24 04:20, Torbjorn Svensson Diaz via Tutor wrote:
> Hello, dear tutors!
>
> Here's my program.
>
>
> import math
>
> print("What is the length of the first leg of the triangle?")
> leg1 = input()
>
> print("What is the length of the second leg of the triangle?")
> leg2 = input()
>
> def hypotenuse(leg1, leg2):
> legs = leg1**2 + leg2**2
> result = math.sqrt(legs)
> return result
>
> x = hypotenuse
> print(x)
>
>
> When I run it in Thonny it says as follows
>
>
> %Run hypotenuse.py
> What is the length of the first leg of the triangle?
> 3
> What is the lenght of the second leg of the triangle?
> 4
> <function hypotenuse at 0x7fa05d5a1940>
This err.msg tells you that x has been set as an alias (second name) of
the function "hypotenuse".
To call the function (and have it return a result) requires a pair of
parentheses and provision of the two arguments (leg1 and leg2).
https://docs.python.org/3/tutorial/controlflow.html#defining-functions
--
Regards,
=dn
More information about the Tutor
mailing list