Function issue - get_force() missing 2 required positional arguments: 'mass' and 'acceleration'

I’m having issues with the exercise “Getting Ready For Physics Class”.

Here is the question:

Define a final function called get_work that takes in mass , acceleration , and distance Work is defined as force multiplied by distance. First, get the force using get_force , then multiply that by distance . Return the result.

And

Test get_work by using it on train_mass , train_acceleration , and train_distance . Save the result to a variable called train_work .

Here is my code:

def get_work(mass, acceleration, distance):
  force = get_force() * distance
  return force

train_work = get_work(train_mass, train_acceleration, train_distance)

However it is returning this error message:

Traceback (most recent call last):
  File "script.py", line 39, in <module>
    train_work = get_work(train_mass, train_acceleration, train_distance)
  File "script.py", line 36, in get_work
    force = get_force() * distance
TypeError: get_force() missing 2 required positional arguments: 'mass' and 'acceleration'

I thought I had to define my arguments within my functions but the error message is telling me otherwise. Not sure what it could be.

Code from whole exercise:

Hi,

You almost have it. Just think, how do you invoke get_force() by itself? If you can call it alone then the answer should reveal itself… (probably :sweat_smile:)

Hi @toastedpitabread,

I think I got it:

def get_work(mass, acceleration, distance):
  force = get_force(train_mass, train_acceleration) * distance
  return force

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.")

This returned the right result, but I’m not sure I understand the concept. Why did I have to declare the mass and acceleration within the get_force function but not distance (it was outside the parenthesis).

I think you mislabeled the variable here. force should be work.
get_force() is a function that takes to variables that you’ve defined (accordingly with the scientific equation.

Work is the force * distance.

So this:

def get_work(mass, acceleration, distance):
  force = get_force(train_mass, train_acceleration) * distance
  return force

is better said thus:

@jrb0831 sorry I misread your code, it should look like this

def get_work(mass, acceleration, distance):
  work = get_force(mass, acceleration) * distance
  return work

you can think of it like this

  • work = x * y
  • but x needs two extra pieces of information so we say:
  • x(mass, acceleration) * y to specify them
  • we get those values by passing them through the parameter in the definition of get_work
2 Likes

Gotcha, thanks for the explanation. I think the concept will start to become more clear as I practice. Right now, it’s super foggy.

1 Like