[Tutor] Print result of function doesn't work
Mats Wichmann
mats at wichmann.us
Sun Jul 21 10:36:39 EDT 2024
On 7/21/24 02:28, dn via Tutor wrote:
> 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
>
in addition, input() returns a string. you appear to intend to use them
as integers, so you need to convert.
More information about the Tutor
mailing list