──────────────────────────────────────

44. Build Your Own Python Program · Build a Score Check Tool

Write a small input-and-report tool from an empty Python file and explain your tests.

Lesson files · lessons/build-your-own-program/score-check-tool

Before you start
- Use input(), int(), strip(), and try/except ValueError to read and validate entries.
- Store values in a list and loop over them to calculate a result.
- Write and test a function with parameters and a return value.

By the end
- Write a complete program from an empty file with input, a calculation function and a report.
- Run the supplied cases and a new input you chose, including an exact-target score.
- Show how to run the tool and explain one design choice and one change you made.

Where you can use it
Help a coach, club organiser or volunteer count how many entries meet a chosen target.

Choose who needs the tool and what the number will help them decide. You might count quiz results that reach a target, jump lengths that reach a mark, or packed kits that reach a minimum. Keep the program’s report format the same so the shared cases work. Sketch the input, calculation and report in your own words.

Start with the smallest version you can test. Use a short list and your counting function first. Then connect the input loop, handle blank or invalid lines, and print the report. Predict the result for a different set of values before running it. Choose one useful improvement and show it with your own case after the main version works.

Predict
Why start with a small list when planning your calculation?
- Programs with longer lists cannot be tested.
- A list with a known result makes the function easier to test on its own.

Worked example (example.py)

def total_labels(labels):
    return len(labels)

print(total_labels(["Blue", "Green", "Blue"]))


Example result
3

Start with a blank editor. Read the target as an integer on the first line. Then read one score per line until done, with spaces and capital letters allowed in the stop word. Ignore blank lines. Count other invalid entries separately. Use a function to count scores at or above the target. Report how many scores were counted, how many met the target and how many entries were invalid. Match the labels shown in Check.

Create an empty file for this project. The included starter.py is empty.

Starter input
10
8

10
12
done

Hint
Begin by testing the function on two numbers on either side of the target and one exactly on it. Add the input loop after the function works.

Case 1. Try the sample
Input
10
8

10
12
done
Expected output
Scores counted: 3
At or above 10: 2
Invalid entries: 0

Case 2. No valid scores
Input
7

unknown
done
Expected output
Scores counted: 0
At or above 7: 0
Invalid entries: 1

Case 3. Negative target and spaces
Input
-1
 -2 
 -1 
bad
0
 DONE 
Expected output
Scores counted: 3
At or above -1: 2
Invalid entries: 1

Project requirement
Start in an empty editor and write the program from the brief.

Project requirement
Use a function to count scores at or above the target. A score exactly on the target counts.

Project requirement
Ignore blank lines, count invalid entries and stop before treating done as a score.

Project requirement
Show a new input, its predicted result and the actual result. Save your working program.

Project requirement
Explain how to run your program and show a small improvement in a separate copy.

Project checklist
I wrote my program from the blank editor and saved it.

Project checklist
I tested an exact-target score, a blank line and a bad entry.

Project checklist
I wrote down the input and result of a test I chose myself.

Project checklist
I can explain my input loop and show a small change.

Marking criterion
Working program (4 points)
The learner demonstrates the correct report for supplied cases and a new input, including equality at the target.

Marking criterion
Independent use of Python (3 points)
The learner explains the input loop and calculation function in their own words and can make a small change from the brief.

Marking criterion
Testing and repair (2 points)
The learner predicts and verifies a new case and can explain a fix or one error condition.

Marking criterion
Using the tool (1 points)
The learner names a real use and tells someone what to enter and how to read the result.

Stretch
Make a separate copy and add a feature for your chosen user, such as showing how many scores are below the target. Keep your original version available for the shared cases.

The ZIP includes added practice files for this lesson. Open its lesson folder and read the included instructions.

Reflect
Describe the person who could use your tool. Explain one step in your code, then write an input and expected result for the next change you would make.

Check your prediction
A list with a known result makes the function easier to test on its own. With a known example you can see whether the calculation works before adding the input loop.
