FAQ: Introduction to Functions - Returns

#1

This community-built FAQ covers the “Returns” exercise from the lesson “Introduction to Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

#2

I use Python 3.7.0 shell to practice my code and i’m having trouble with this section of the functions. When i try to return a function it comes up as a syntax error, specifying that the next line of code that i create a variable in is an invalid syntax. Here is an example:

``````Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
>>> def calculate_age(current_year, birth_year):
age = current_year - birth_year
return age
my_age = calculate_age(2018, 1993)

print("I am " +  str(my_age) + " years old and my dad is " + str(dads_age) + " years old.")
SyntaxError: invalid syntax
>>>
``````

I literally just copied and pasted it onto the shell.

#4

The shell does not permit pasting of multiple statements since it is first and foremost, a command line interpreter.

First, paste in the function and Enter.

``````>>> def calculate_age(current_year, birth_year):
age = current_year - birth_year
return age

>>>
``````

Then paste in and Enter one line at a time from the other three.

#6

I thought it a good idea to practice passing variables as function params. I also have done a little bit of documentation practice for the function.
Next step, pass dict values as func. params!

``````my_yb = 1950