[Tutor] Return Statement error
William Becerra
wbecerra1 at gmail.com
Sun Oct 12 16:38:54 CEST 2014
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
I want my application to compare x and y and return either 1, -1 or 0.
I'm using IDLE
Here is my code:
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 "Please insert a Valid character"
When I press F5 to run my code a new window called syntax error appears
The window says the following
There's an error in your program:
***'return' outside function (C:/Users/William/Desktop/Python
Files/Function compare.py, line6)
What am I doing Wrong?
I noticed that if i substitute all the return keywords with print the code
runs correctly.
However I want to use return as I am trying to learn how it works.
Thank You.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141012/094c92be/attachment.html>
More information about the Tutor
mailing list