Learn-python-3 - projects, physics-class

Hi! I just got back to learning a bit of python and well, I’m stuck at the project Physics-Class.
Specifically on step #9, I am having issues with getting the following code to work:

def get_energy(mass, c = 3*10**8):
  return mass ** c

bomb_energy = get_energy(bomb_mass)
print(bomb_energy)

The steps in question:
8.
Define a function called get_energy that takes in mass and c .

c is a constant that is usually set to the speed of light, which is roughly 3 x 10^8. Set c to have a default value of 3*10**8 .

get_energy should return mass multiplied by c squared.

Test get_energy by using it on bomb_mass , with the default value of c . Save the result to a variable called bomb_energy .

In the console it always returns 1 when printing bomb_energy while it should print 90000000000000000

What is it that I’m doing wrong, it feels like I’m just staring at a wall constantly at the moment.
I have a feeling that its going wrong at the default value of the parameter in the function get_energy.

https://www.codecademy.com/courses/learn-python-3/projects/physics-class

1 Like

Does this conform to that specification? …

  return mass ** c

See Learn Python: Syntax: Exponents.

1 Like

I’m really not understanding it at all then.

Could you be a tad more specific, I think the “return mass” is correct, but that I am not getting the “mass multiplied by c squared” correct.

If i were to write it down it would look something like this:
X * Y^2 correct?

1 Like

One of the code examples provided by the page that is linked above is …

# 8 squared, or 64
print(8 ** 2)

So to square something, use 2 as the exponent. Specifically, to square c, we do this …

c ** 2

We need to multiply mass by that quantity, and return the result, so we have …

  return mass * c ** 2
3 Likes

Ahh, now I get it, I’ve had several attempts that looked like the example you provided.
But always returned 1, because I didn’t square c properly.

2 Likes