the number cruncher - stats and storage
A coding challenge
Imagine you're a dedicated sports coach tracking your team's performance data. You need a clever computer program that can help you log individual scores from training sessions, then quickly give you insights into how the team is doing. You want to see the average score, find the middle score (that's the median!), and even spot the most common score (that's the mode!). Plus, you'll need a way to save all that valuable data for later review. Can you build a tool that helps you crunch these numbers and keep them organised?
Required Prior Learning
Understanding of basic data types such as whole numbers (integers) and decimal numbers (floats).
How to use lists to store multiple pieces of data in order.
Using `
input()` and `print()` for user interaction.Working with `
while` loops for repetitive tasks and `if/elif/else` statements for making choices in your code.Use
Investigate & PredictTake a look at the Python code in the sandbox below. It's designed to collect numbers from you until you decide to stop. Run the code a few times, enter different numbers, and then type 'stop'. Pay close attention to what the program prints out at the end.
Prediction Questions
1
If you type "STOP" (all capital letters) when prompted, what do you predict will happen and why?
2
What is the purpose of the `
entered_numbers` variable, and what type of data structure is it?3
If you enter the numbers 10, 20, 30, and then type 'stop', what will the output for "Total count:" be?
Modify
Tweak & ExperimentTake the starter code in the widget above and experiment with the following changes:
1
Change the word the user types to finish the input from `
'stop'` to `'finish'`. Remember to update both places in the code!2
Add a new line of code right after `
print("Total count:", len(entered_numbers))` to also print the sum of all the numbers collected. (Hint: there's a handy built-in function for this!)3
Modify the line `
number = float(user_input)` to `number = int(user_input)`. Now, try entering a decimal number like `5.5`. What happens, and why?Create
The Core ChallengeNow it's time to build your very own 'Number Cruncher' program to help that sports coach! Your program should be user-friendly, allowing them to enter as many scores as they need, and then giving them options to analyse the data or save it for later.
Success Criteria
Your program must allow the user to continuously enter numbers until they choose to stop or perform an action.
It must be able to calculate and display the average of all the numbers entered so far.
Your program should also calculate and display the median of the numbers. Remember to sort the numbers first!
It needs to identify and display the mode (the most frequent number) from the list. If there are multiple modes, display them all.
Include an option for the user to save their current list of numbers to a text file.
Add another option to load numbers from a previously saved text file into the program.
Handle situations where no numbers have been entered before trying to calculate statistics, providing a helpful message.
Extension: Make your program robust by handling cases where the user enters text instead of a number, or tries to load a file that doesn't exist.
Test Your Code
Run your code and check it against the expected behaviour below:
User Action
Expected Output
Purpose of Test
1. Enter `10`, `20`, `30`, `40`, `50`. Then choose 'Average'.
Average: `30.0`
Verify average calculation with valid input.
2. Enter `1`, `5`, `2`, `5`, `3`. Then choose 'Median' and 'Mode'.
Median: `3.0`. Mode: `5.0`
Check median and mode logic, including sorting and frequency.
3. Enter `7`, `3`, `7`, `1`, `3`. Choose 'Save' (e.g., to `scores.txt`). Restart program. Choose 'Load' from `scores.txt`. Then choose 'Average'.
Program saves numbers. After loading, Average: `4.2`
Confirm file saving and loading functionality.
4. Start program, immediately choose 'Average' (without entering any numbers).
A message like "No numbers entered yet!"
Test for graceful handling of empty data sets.
Don't forget to print your code and output to a PDF file and send it to your teacher.
Last modified: October 22nd, 2026
