Getting Ready for Physics Class task for Python - Functions task

Hi, just a quick question, I am currently doing the Learn Python 3 course on here. I managed to do exactly what the developer in the project walkthrough video done step by step, exactly the same apart from one part. From task 11 onwards during the get_work function, I done it slightly different but still got the same output. My question is was I wrong to do it this way?

My code:

train_mass = 22680

train_acceleration = 10

train_distance = 100

def get_force(mass, acceleration):
return mass * acceleration

def get_work(distance):
return get_force(train_mass, train_acceleration) * distance

train_work = get_work(train_distance)
print(“The GE train does " + str(train_work) + " Joules of work over " + str(train_distance) + " meters.”)

I just used the get_force() function within my function and still got the same.

It’s my first post on this forum, so apologies if I haven’t given the whole information or if you need any other info.

1 Like

For the benefit of others who may not have seen the video walkthrough, in the video they call the get_force function and assign its value to a variable of force which is subsequently used in the calculation of work in get_work.

As to whether you’re wrong… that’s kind of subjective. One of the goals for the Python language was to emphasise readability, on the basis that code is read a lot more often than it gets written.

In this instance, we’re dealing with basically a one-liner… so I don’t think that your solution is difficult to read and understand. Equally, you’re only using the value returned from get_force() once so there’s no desperate need to store it in a variable.

I’d say there’s no issue with the way you’ve solved the task, but others may disagree with me. :slight_smile: