 # Getting Ready for Physics Class - question on the get_work function

Hi there!

I’ve completed the Getting Ready for Physics Class project but wanted some clarification on an aspect of the code.

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 = 310**8):
return mass * c
c

bomb_energy = get_energy(bomb_mass)

print(bomb_energy)

print(‘A 1kg bomb supplies ’ + str(bomb_energy) + ’ Joules.’)

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

For the function get_work why do I have to re-state the variables of mass and acceleration in the line “force = get_force(mass, acceleration)” if they’ve already been previously stated as part of the get_force function? If I left the variables blank would it not assume the defaults of (mass, acceleration)?

When you define the get_force function, you also define parameters that will work within the scope of that function (but not outside). Therefore the names don’t carry over.

Here’s an illustration of that, with the names purposefully switched. Note, you wouldn’t normally code this confusingly on purpose, but this example does highlight how parameter scope works.

``````def first_function(parameter1):
return paramater1

def second_function(parameter1, parameter2):
something = first_function(paramater2) * paramater1
return something

second_function(2, 3)

#returns 6
``````
4 Likes

Great - thank you for your help!

1 Like