Re: Print result of function doesn't work

dn via Tutor <[email protected]> Sun, 21 Jul 2024 20:28:34 +1200
Newsgroups gmane.comp.python.tutor
Organization DWM
Message-ID <[email protected]>
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
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor