I’m following this guide and I can’t get a basic function to work.
birthday2.py
def happyBirthdayEmily(): #program does nothing as written
print("Happy Birthday to you!")
print("Happy Birthday to you!")
print("Happy Birthday, dear Emily.")
print("Happy Birthday to you!")
So following the guide I type this:
>>>import birthday2
>>>happyBirthdayEmily
This is the error I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'happyBirthdayEmily' is not defined
What Am I missing here?
You are missing parentheses after
happyBirthdayEmilyand a module reference. Do it like this:The parens identify it as a function call, and the
birthday2.at the beginning just says, “Use the functionhappyBirthdayEmily()from thebirthday2module.” This is structured like this, because if you had another function (not inbirthday2) that was also calledhappyBirthdayEmily(), the python interpreter basically wouldn’t know which one to use.