Re: [Tutor] Return problems
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
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