Interpretation error!


#1



https://www.codecademy.com/courses/introduction-to-python-6WeG3/1/3?curriculum_id=4f89dab3d788890003000096#


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.


#2

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?

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

x = False
y = False

#3

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

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


#4

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 it..by 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?)


#5

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