[Tutor] Return Statement error
William Becerra
wbecerra1 at gmail.com
Mon Oct 13 07:48:53 CEST 2014
I am familiar with funtions, i didn't realize i had to write the return
statement inside a function...Thank you all..that was very helpful
On 13 Oct 2014 01:03, "Steven D'Aprano" <steve at pearwood.info> wrote:
> On Sun, Oct 12, 2014 at 04:38:54PM +0200, William Becerra wrote:
> > Hello, I'm new to programming. I'm using Python 2.7.8 and Windows 8 OS
> > I was making an application to see if I understand how the return
> statement
> > works
>
> The `return` statement can only be used inside a function. That means
> you have to start off with a `def` line, and indent your code.
>
> Have you learned about functions yet? If not, perhaps you might prefer
> to forget about `return` until you do. Otherwise, if you take the code
> you wrote, indent it, and put a function declaration at the top, you
> should be able to use `return` successfully:
>
> def compare():
> print "Please write a value for x"
> x = raw_input()
> print "Please write a value for y"
> y = raw_input()
> if x > y:
> return 1
> elif x < y:
> return -1
> elif x == y:
> return 0
> else:
> return "this will never happen"
>
>
> Then, once you have defined your function, you can call it:
>
> result = compare() # don't forget the parentheses ()
> print "And the result is", result
>
>
>
> --
> Steven
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141013/402d6b0a/attachment-0001.html>
More information about the Tutor
mailing list