Re: [Tutor] Return problems

2018-04-07 Thread Steven D'Aprano
On Fri, Apr 06, 2018 at 05:50:35PM -0700, Roger Lea Scherer wrote:
> So I've examined my educational material, I've perused the python
> documentation and for the life of me I can't figure out why return doesn't
> print a result in the IDE. I use print, the program acts as expected. What
> am I missing?

What IDE are you using?


In the standard Python interactive interpreter, calling findHypot(3, 4) 
ought to print 5. The same applies in IDLE, or iPython. That's a 
convenience feature for interactive use.

But if you use IDLE to run the file as a script, using the Run Module 
command, then you're running in "batch mode", so to speak, and results 
aren't printed unless you explicitly use the print command.

So try changing your script to:

print(findHypot(3, 4))


for Python 3, or

print findHypot(3, 4)

for Python 2.



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Return problems

2018-04-07 Thread Alan Gauld via Tutor
On 07/04/18 01:50, Roger Lea Scherer wrote:
> So I've examined my educational material, I've perused the python
> documentation and for the life of me I can't figure out why return doesn't
> print a result in the IDE. I use print, the program acts as expected. What
> am I missing?

The fact that return doesn't print anything it just returns
a value to the caller.

I suspect that you are getting confused by the behaviour of
the interactive prompt (>>>) which automatically prints
results.  But that is purely a feature of the >>> prompt
designed to make developing/debugging code easier.

In regular Python code execution values are only printed
when you ask for them to be by using print. And if you
think about it, that's a good thing, otherwise the screen
would quickly fill with a mess of intermediate values
the user doesn't need.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Return problems

2018-04-07 Thread Roger Lea Scherer
So I've examined my educational material, I've perused the python
documentation and for the life of me I can't figure out why return doesn't
print a result in the IDE. I use print, the program acts as expected. What
am I missing?

import math

from decimal import Decimal

def findHypot(a, b):
c = math.sqrt((a ** 2) + (b ** 2))
if c == (round(c)):
return round(c)
else:
return round(c, 4)

findHypot(3, 4)

from the IDE:

= RESTART: C:\Users\Roger\Documents\GitHub\LaunchCode\hypotenuse.py
=
>>>

Thank you as always.

-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor