[Tutor] flow problem with a exercise

Roelof Wobben rwobben at hotmail.com
Thu Aug 19 21:01:55 CEST 2010


Hello, 

 

I have this exercise:

 

Now write the function is_odd(n) that returns True when n is odd and False otherwise. 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
   

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

 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100819/70832a6f/attachment-0001.html>


More information about the Tutor mailing list