What you'll build
Write a function that takes a score and returns a verdict, then use what it hands back — count how many scores pass. The exercise that makes return click: the caller decides what to do with the answer.
Requirements
The must-do parts. If any are missing, we'll ask you to take another pass.
- Define a function
verdict(score)thatreturns"Pass"for 50 or above and"Fail"below — decide it withif/elseandreturnfrom each branch. - Make a list of at least five scores and use a
forloop to print the verdict for each. - Keep a counter that uses the returned value: add one to
passesevery timeverdict(score)comes back"Pass". - After the loop, print how many passed out of the total using
len().
- Add a
"Merit"band for 70 and above, returned from its own branch. - Return early for an invalid score (below 0 or above 100) with a clear message instead of a verdict.
Examples
What your program should look like when it runs. Lines starting with $ are typed by you; the rest is your program.
72 -> Pass
48 -> Fail
90 -> Pass
55 -> Pass
30 -> Fail
3 of 5 passed.Where to start
Copy this scaffold into a new file. You don't have to use it — it's just a friendly nudge.
# Pass-or-fail verdict function
def verdict(score):
# TODO: return "Pass" for 50+ and "Fail" below
pass
scores = [72, 48, 90, 55, 30]
passes = 0
# TODO: loop over scores, print each verdict,
# and count how many came back "Pass"
# TODO: print how many passed out of len(scores)How we'll grade it
Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.
| Check | What we look for | Pt |
|---|---|---|
| It runs | Prints a verdict for every score and a final count without crashing. | 1 |
| Function returns | `verdict(score)` returns the word — it does not print inside. Boundaries are right: 50 passes, 49 fails. | 1 |
| Uses the return value | The pass counter is driven by what the function returns, not by re-checking the score outside the function. | 1 |
| Count is correct | The final tally matches the scores, and it is reported out of `len()` of the list. | 1 |