Python - Functions (freedom project)

Hi,

I have a question on question 9 of the Python 3 Freedom Project (Physics Class).

I am not quite sure why the below code that I have used would not work?

def get_energy(mass,c=310**8):
return mass
c**2

get_energy(bomb_mass)
print(get_energy)

The solutions shown set
bomb_energy = get_energy(bomb_mass)
print(bomb_energy)

Is there a reason for my code not working?

Thank you!

It looks like you have missed a * between mass and c in your return statement.

def get_energy(mass,c=310**8):
  return mass*c**2
1 Like

Hi,

Thank you but I did include that * - must have not been pasted properly onto the forum!

1 Like

Calling the get_energy() function does not save the value returned unless you assign it to a variable like you see they did in the solution with bomb_energy = get_energy(bomb_mass).

You will want to call the get_energy() function within the print function to get it to print the return value.

print(get_energy(bomb_mass))
2 Likes