[Tutor] flow problem with a exercise

Joel Goldstick joel.goldstick at gmail.com
Thu Aug 19 21:27:01 CEST 2010


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

>  Hello,
>
> I have this exercise:
>
>
> Now write the function is_odd(n) that returns True when n is odd and Falseotherwise. Include doctests for this function as you write it.
> Finally, modify it so that it uses a call to is_even to determine if its
> argument is an odd integer.
>
> So I thought of this :
>
> def is_even(argument):
>     remainder= argument%2
>     if remainder == 0 :
>         return True
>     else :
>         return False
>
> def is_odd(argument):
>   uitkomst=is_even(argument)
> return uitkomst
>

NOTE that your return statement is not indented properly.  It must line up
under 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.
>
>
> 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.
>
> I work on a Win7 machine with Python 2.7
>
> Roelof
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100819/4e7a4559/attachment.html>


More information about the Tutor mailing list