How can I enter my code into a python shell?

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.

2 Likes