Help - Getting Ready For Physics Class Python Lesson - Questions

This is the project link: Physics Class

Okay so I finished the project and it all went well but I’m left with unanswered questions about a part of it. This is my code and my questions is below it:

train_mass = 22680
train_acceleration = 10
train_distance = 100

bomb_mass = 1
#function to convert fahrenheit to celsius
def f_to_c(f_temp):
  c_temp=(f_temp-32)*5/9
  return c_temp
f100_in_celsius=f_to_c(100)
print(f100_in_celsius)

#function to convert celsius to fahrenheit
def c_to_f(c_temp):
  f_temp=c_temp*(9/5)+32
  return f_temp
c0_in_celsius=c_to_f(0)
print(c0_in_celsius)

#Force function
def get_force(mass,acceleration):
  return mass*acceleration
train_force=get_force(train_mass,train_acceleration)
print(train_force)

#exercise 7
print("The GE train supplies "+str(train_force)+" Newtons of force")

#energy and bomb function
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.")

#11 Work Function
def get_work(mass,acceleration,distance):
  force=get_force(mass,acceleration)
  return force*distance
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.")

Okay, so my question is: at comment #11, why does force=get_force get me any value ? in order to to do the calculation at #force function I had to specify inputs for the mass and acceleration parameters, i had to write get force(train_mass,train_acceleration). Initially I thought it would get me the results from that force function, but when I looked, the train_force variable is the one getting me the result of 226800 and not the get_force function alone… I would like to understand what happens before moving on with the lessons.

Another question is why do I need to write force=get_force(mass,acceleration)? I just noticed that by changing the last part of the code the result is the same:

#11 Work Function
def get_work(mass,acceleration,distance):
  return mass*acceleration
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.").

Thank you and sorry for the long message.

Please repost your code and format it using the </> icon in the toolbar that appears along the top of the text area when you’re typing your reply. It’s impossible to look at your code when it’s not formatted.

Sorry. First time here :slight_smile:

See if you can follow this. Red arrows trace the path of that original 22680, yellow follows the calculations and returned values.

In this particular exercise, you apparently do not. However, the point of the exercise is to get you comfortable with re-using functions that you have written. If there were several other functions, for instance, that needed force, it would be convenient to have this function available, expecially in a more realistic situation where you needed the solution of a differential equation rather than simply F = M * A.

1 Like

force is a vector computed by multiplying mass (a scalar) by acceleration (also a vector).

F = m * a

work is a vector computed by multiplying force times distance (both of which are vectors).

W = F * d.

More correctly, distance is a scalar, which when written as a vector takes the name, displacement. Distance has no sense of direction, whereas displacement does have a sense of direction, hence a vector.

While this exercise is more focused on relating scalar concepts for the sake of mechanics, in the real world we would treat vectors as vectors, and would include the dimensional analysis that resolves to a final unit of measure.

F => N             # Newtons
m => kg            # kilograms
a => m / s ** 2    # meters per second per second

so the constant of proportionality for this analysis is,

|  N * s ** 2  |
|  ----------- |
|    kg * m    |

So we have this to resolve…

 F  =  (N) m (kg) * d (m) / t (s ** 2)

We see that the units for kg, m and s ** 2 all cancel out, leaving only Newtons as the final unit.

How do you write function f_to_c without c_temp as an input?

c_temp (or whatever you choose to call the temperature in Celsius inside of the function) is the output. The input is f_temp, the temp in Fahrenheit.

1 Like

Hi, I have two problems with this exercise, one is rather strange, I get this output in a part where it should print info about Newtons force provided by train, I get this:

A 1kg bomb supplies <function get_energy at 0x7fdef013be18> Joules.

Somebody knows what’s wrong?

Another is that in a last exercise where you are testing newly made get_work function, I get this error:

Traceback (most recent call last):
File “script.py”, line 28, in
train_work=get_work(train_mass, train_acceleration, train_distance)
File “script.py”, line 27, in get_work
return (force)*(distance)
TypeError: unsupported operand type(s) for *: ‘function’ and ‘int’

This 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_celsius=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):
  c=3*10**8
  return mass*c**2
get_energy(bomb_mass, c=3*10**8)
bomb_energy=get_energy
print ("A 1kg bomb supplies "+str(bomb_energy)+" Joules.")
def get_work(mass, acceleration, distance):
  force=get_force
  return (force)*(distance)
train_work=get_work(train_mass, train_acceleration, train_distance)

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

Let’s focus on this statement:

bomb_energy=get_energy

What is the purpose of that statement, and does it accomplish that purpose?