# The commuter’s puzzle

Yuri lives in Oxford, UK and commutes by train to his work place in London every working day of the week (5 days a week).

One evening, Yuri spot the Moon through the train window and asked himself the following question:

“In how many years will I have travelled the equivalent distance of going to the Moon and back due to my daily commute?”

On a piece of paper Yuri has gathered some data needed to answer this question:

 Description Value Distance between Oxford and London: 60 miles Distance between planet Earth and the Moon: 383,400km Number of km in 1 mile: 1.609km Number of working days per week: 5 Number of weeks in a year: 52

He has also drawn the following flowchart to help him find the answer. His intention was to then use some Python code to implement this flowchart and work out the answer to his question. This algorithm is a sequencing algorithm based on the following steps:

1. Work out the total distance travelled over a year (in km).
2. Work out the distance of a return journey to the Moon (in km).
3. The number of years can be calculated by dividing the distance of a return journey to the Moon by the total distance travelled over a year.

#### Python Code

You can use the above flowchart to complete the Python code for this sequencing algorithm.

[pms-restrict display_to=”not_logged_in” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ display_to=”not_subscribed” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ message=” “]

#### Solution...

You are viewing this solution as part of your full membership subscription!

Python Code

#### Python Code

```#The commuter's puzzle - www.101computing.net/to-the-moon-and-back

dailyCommute = 60 * 2
weeklyCommute = 5 * dailyCommute
yearlyCommute = 52 * weeklyCommute

#Convert yearly distance in km
yearlyDistance = yearlyCommute *1.609

moonTrip = 384400*2

years = moonTrip / yearlyDistance

print("Yuri would have travelled the equivalent of going to the Moon and back in " + str(years) + " years!")
```
[/pms-restrict]

Did you like this challenge?

Click on a star to rate it!

Average rating 4.2 / 5. Vote count: 74

No votes so far! Be the first to rate this post.

As you found this challenge interesting...