# Python 3 physics class project, syntax error

Hello, I have written this code for Python 3 physics class project. It is showing the following error:
File “script.py”, line 19
def get_energy(mass, c = 3*10**8):
^
SyntaxError: invalid syntax

Here is my code:

train_mass = 22680
train_acceleration = 10
train_distance = 100

bomb_mass = 1
def f_to_c(f_temp):
c_temp = (f_temp - 32) * 5/9
return c_temp
f100_in_celsuis = f_to_c(100)
def c_to_f(c_temp):
f_temp = (c_temp * (9/5) + 32)
return f_temp
c0_in_fahrenheit = c_to_f(0)
def get_force(mass, acceleration):
return mass * acceleration
train_force = get_force(train_mass, train_acceleration)
print(train_force)
print(“The GE train supplies " + train_force + " Newtons of force.”
def get_energy(mass, c = 3*10**8):
return mass * c ** 2
bomb_energy = get_energy(bomb_mass)
print(“A 1kg bomb supplies " + bomb_energy + " Joules.”)
def get_work(mass, acceleration, distance)
force = get_force(mass, acceleration)
work = force * distance
return work
train_work = get_work(train_mass, train_acceleration, train_distance)
print("The GE train does " + train_work + “Joules of work over " + train_distance + " meters.”)

Can someone please rectify my mistake, I am unable to find the solution to this problem.

Hello, @jasmeet5000, and welcome to the Codecademy Forums!

When a `SyntaxError` occurs at the beginning of a line of code, take a careful look at the previous line.

When you post code, it is best to format it for proper display, See How to ask good questions (and get good answers) for advice on this.

3 Likes

Yeah, I saw that now. Thank you very much. 1 Like

You’re trying to print the value of `train_force`, this is causing a `SyntaxError` because it isn’t a string. Can you think of a way to make it a string?

1 Like

That would actually raise a `TypeError`. See the following interactive session:

``````>>> train_force = 70
>>> print("The GE train supplies " + train_force + " Newtons of force.")
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
print("The GE train supplies " + train_force + " Newtons of force.")
TypeError: can only concatenate str (not "int") to str
``````

Yes, that would resolve the `TypeError` issue, assuming the `SyntaxError` issue has also been resolved.

1 Like

Thanks, everyone in this forum, I have finally completed my project Here’s the final code and it works!!!

``````train_mass = 22680
train_acceleration = 10
train_distance = 100

bomb_mass = 1
def f_to_c(f_temp):
c_temp = (f_temp - 32) * 5/9
return c_temp
f100_in_celsuis = f_to_c(100)
def c_to_f(c_temp):
f_temp = (c_temp * (9/5) + 32)
return f_temp
c0_in_fahrenheit = c_to_f(0)
def get_force(mass, acceleration):
return mass * acceleration
train_force = get_force(train_mass, train_acceleration)
print(train_force)
print("The GE train supplies " + str(train_force) + " Newtons of force.")
def get_energy(mass, c = 3*10**8):
return mass * c ** 2
bomb_energy = get_energy(bomb_mass)
print("A 1kg bomb supplies " + str(bomb_energy) + " Joules.")
def get_work(mass, acceleration, distance):
force = get_force(mass, acceleration)
work = force * distance
return work
train_work = get_work(train_mass, train_acceleration, train_distance)
print("The GE train does " + str(train_work) + " Joules of work over " + str(train_distance) + " meters.")
``````
1 Like

You are welcome. We’re glad it worked.

Link to project instructions: Learn Python 3: Getting Ready for Physics Class

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.