[Tutor] Print result of function doesn't work
Torbjorn Svensson Diaz
torbjorn_svensson_diaz at yahoo.com
Sat Jul 20 12:20:11 EDT 2024
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>
I have the same trouble when I run the program as a script in the
terminal but when I use interactive mode I have no difficulties.
The same program in Scheme is
(define (hypotenuse leg1 leg2) (sqrt (+ (expt leg1 2) (expt leg2 2))))
(hypotenuse 3 4)
and works wonders. Why doesn't my Python program run? What do I do
wrong? Can someone help me out? Perhaps give me some pointers as to what
I should learn?
Thanks in advance and best regards,
More information about the Tutor
mailing list