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 |
|---|---|
| Mon | 0 |
| Tue | 5 |
| Wed | 8 |
| 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.
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 |
|---|---|
| Mon | 0 |
| Tue | 5 |
| Wed | 8 |
| Thu | -2 |
| Fri | -10 |
See this tip on how to output data in Python
A bus runs for a 4 week period. The data that the system now needs to process is:
| day | Bus A |
|---|---|
| Mon1 | 0 |
| Tue1 | 5 |
| Wed1 | 8 |
| Thu1 | -2 |
| Fri1 | -10 |
| Mon2 | 3 |
| Tue2 | 6 |
| Wed2 | -1 |
| Thu2 | 0 |
| Fri2 | -8 |
| Mon3 | 0 |
| Tue3 | 0 |
| Wed3 | 0 |
| Thu3 | 0 |
| Fri3 | 4 |
| Mon4 | 0 |
| Tue4 | 0 |
| Wed4 | 0 |
| 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:
Here is a suggested solution - it doesn't show how to display the statistics but hopefully you know how to do that!
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!
You have completed Part A of this coding challenge.
Compare your work with the sample solution shown in this video.
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!