is_even = "x"
if x % 2:
    return True
      return False

when i click on save&submit it was shoeing me like this. could any one tell me where my code went wrong?

Oops, try again. Your code appears to raise an exception, see the console window for the error message!

File "python", line 3
SyntaxError: 'return' outside function


return can only be used inside a function? You don't have a function?


can i use return statement like this
print True


that is a print statement, not a return statement?

step 1 of the instructions is clearly to make a function:

Define a function is_even that will take a number x as input

Do you remember how to make a function? You can always revisit exercises you already completed, or check documentation


hi i had written my program as for instructions. could any one tell me where my program went wrong?


so on line 2 you have the following code:

if x % 2:

so lets say x = 24, 24 %2 is zero.

so if numbers are even, the remainder is zero, so we should if the remainder equals (==) zero


thank you i got the code. i did understand why we have to modify this step as follows.
if x % 2 == 0:

and when we pass the if statement like this. whey cont program is executed

if x % 2:

could u please explain me?


it not that we can't do, but its slightly more complicated.

For even numbers the remainder is zero, for odd number the remainder is one (makes sense, right?)

So then if will evaluate the following:

if 0:

for even numbers, and:

if 1:

for odd numbers.

in python, 0 is considered false, and 1 is considered true. So this would mean, you need to swap return true and return false


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.