[Tutor] flow problem with a exercise

Wayne Werner waynejwerner at gmail.com
Thu Aug 19 21:43:04 CEST 2010


On Thu, Aug 19, 2010 at 2:01 PM, Roelof Wobben <rwobben at hotmail.com> wrote:

> <snip>
>
def is_odd(argument):
>   uitkomst=is_even(argument)
> return uitkomst
>
> even=is_odd(1) ;
> if even==True :
>   print "Even getal"
> if even==False:
>     print "Oneven getal"
>
>
> But now I get this error message :
>
> return uitkomst
> Syntax error : return outside function.
>

Check your indention. In the email your return is at a different level than
your function. Always use 4 spaces. If your editor can't convert, you need a
better editor!


>  In my opinon even calls is_odd , then uitkomst calls is_even which gives a
> true or false to uitkomst. So return uitkomst gives the outcome to even.
> But the intepreter thinks otherwise.
>

Well, good thing opinions don't count for much when talking to a computer ;)

You are correct that uitkomst contains the result of is_even, but your
return is on a different indention level. Whitespace is significant here.

If I were you, I would define is_odd this way:

def is_odd(argument):
    uitkomst = not is_even(argument)
    return uitkomst


>  I work on a Win7 machine with Python 2.7
>

Good job providing both the traceback and your system. They make every
problem easier to debug.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100819/fa726be1/attachment.html>


More information about the Tutor mailing list