1.Before we Begin


#1

Here's my code:

def answer():
return ("42")

I believe that it should work,although I am getting an error as "Oops, try again.
Your function should return the number 42."


#2

Hi your return should be like that

return 42

#3

Thanks for the reply although the fix was a "tab" away :stuck_out_tongue:


#4

You should do return 42 instead


#5

Hello wizmarco,
I have a question, in this particular case, does these codes:

def answer():
return 42

has the same meaning with these codes:

answer = 42

Sometimes I am a little bit confused between these 2 things:
1) "defining a function, then return it to a certain value"
and
2) "assigning a certain value" to a variable

I understand that in similar exercises like this one, these 2 things perform the same thing and produce same results. Please correct if I am wrong, just want to know deeper. Thanks :smiley:


#6

No it isn't, @nguyengiang2004. When a function returns a value, it usually performs some action on arguments that are passed to it by the user. A variable has to be manually set by the user and doesn't need arguments in order to work... Hope this clears it out


#7

HI they are different one is a function the other a variable while a function return value in a variable you store value

the same thing and produce same results

yes they will produce the samething

#the function

def answer():
    return 42

#call the function
answer()

#Output
42

#the variable

answer = 42
print answer

#Output
42

But they still different.


#8

Ah...now I understand. So the variable just stores value, or like @bartholomewallen said, that it

and just stops at that, while with function, the users can add on further commands for it.


#9

Perfect, @nguyengiang2004!


#10

yah, I think I can stop digging at this point, when I learn more, there'll be more fun.
Thank you guys @wizmarco and @bartholomewallen :balloon: