FAQ: Introduction to Functions - Returns


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:

Computer Science
Data Science

FAQs on the exercise Returns

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

Ask or answer a question about this exercise by clicking reply (reply) below!

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

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

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!


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
Type "copyright", "credits" or "license()" for more information.
>>> def calculate_age(current_year, birth_year):
  age = current_year - birth_year
  return age
my_age = calculate_age(2018, 1993)
dads_age = calculate_age(2018, 1953)

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.


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.