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.

2 Likes