Interpretation error!


Oops, try again. The variable spam should have the value True!

I can't see to find the error. This is the code I ran. Can anyone tell me where I'm wrong?

def spam():
spam = True
return spam
print spam()

def eggs():
eggs = False
return eggs
print eggs()

Replace this line with your code.


Back to instruction of this exercise..

Create a variable called spam and assign it the value of True.
Create a variable called eggs and assign it the value of False.

You're creating function?why?

If I had to create variables x and y and assign False values to them.
I'd do this..

x = False
y = False


The code actually runs... but I keep getting this error message

''Oops, try again. The variable spam should have the value True!''


Hi @seghe
When they asked to set value of variables spam and eggs to True and False correspondingly.
It means they asked to create them outside of any function, as Global variables.

When you create them inside the function.
They exist till function is called and you print them.
After that they (spam and eggs) have no existence .
They're Local variables.
there is a way to pass making them global variables..
You can make them global using global keyword. (Just for experimentation ,As It is not intention of this exercise)

(I assume that you already done this exercise and trying to experiment with it?)


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