Part B

Buses - Part A

 

The local high school uses buses to transport students to school.

Each bus runs from Monday to Friday.

You are conducting a survey to analyse the punctuality statistics of a bus for 1 week. Here is some sample data for a bus:

day Bus A
Mon0
Tue5
Wed8
Thu-2
Fri-10

0 means the bus was on time when delivering students to school.

A positive number means that the bus was early eg 8 means the bus was 8 minutes early.

A negative number means that the bus was late eg -2 means that the bus was 2 minutes late.

Part A

Task 1 - setting up the data

Using arrays, design a system to allow data to be entered for 1 week.

The data should be displayed meaningfully, for example:

day Bus A
Mon0
Tue5
Wed8
Thu-2
Fri-10

See this tip on how to output data in Python

Task 2 - adaptive maintenance

A bus runs for a 4 week period. The data that the system now needs to process is:

day Bus A
Mon10
Tue15
Wed18
Thu1-2
Fri1-10
Mon23
Tue26
Wed2-1
Thu20
Fri2-8
Mon30
Tue30
Wed30
Thu30
Fri34
Mon40
Tue40
Wed40
Thu4-13
Fri4-1

Adapt your program so that data can be entered into an array for a 4 week period.

Output the results as shown above.

Calculate and display the following statistics:

  • the number of times the bus was late
  • the number of times the bus was early
  • the number of times the bus was on time

Here is a suggested solution - it doesn't show how to display the statistics but hopefully you know how to do that!

Task 3 - adaptive maintenance

Adapt your program such that a user is prompted to enter a valid day eg Fri.

The program will display the average time the bus was late on that day.

Hint #1: You could create a menu eg:

Enter a number to choose a day:

1. Mon

2. Tue

3. Wed

4. Thu

5. Fri

This might make it easier to validate the input and use the value to process indexes in the array.

 

Hint #2: Using the modulus operator, %

0%5 = 0

1%5 = 1

2%5 = 2

3%5 = 3

4%5 = 4

5%5 = 0

6%5 = 1

7%5 = 2

...

Can you see how this concept can help you to solve this problem if we are working with array indexes? Every 5th number in the array represents the same day...

Here is a suggested solution - it doesn't show how to display the statistics but hopefully you know how to do that!

Complete

You have completed Part A of this coding challenge.

Compare your work with the sample solution shown in this video.

Decompose the problem

One tip is to make a list of things that your program needs to do before you start coding - you could do this as comments in Python eg

#create an empty array

#create a loop to do something 5 times

#ask the user to input a number in the loop

#append the number to the array in the loop

#calculate statistics in the loop

#display all data and statistics after the loop

Then... start coding!

Part B