AssignmentsWeek 02 · Decisions and structurePass-or-fail verdict function
wk02.p12Practice exerciseWeek 02 · Decisions and structureOpen · due this week

Pass-or-fail verdict function

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.

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.

  1. Define a function verdict(score) that returns "Pass" for 50 or above and "Fail" below — decide it with if / else and return from each branch.
  2. Make a list of at least five scores and use a for loop to print the verdict for each.
  3. Keep a counter that uses the returned value: add one to passes every time verdict(score) comes back "Pass".
  4. After the loop, print how many passed out of the total using len().
Bonus, if you're feeling brave
  • 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.

Example cell runs
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.

CheckWhat we look forPt
It runsPrints 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 valueThe pass counter is driven by what the function returns, not by re-checking the score outside the function.1
Count is correctThe final tally matches the scores, and it is reported out of `len()` of the list.1
Ready?
Hand it in
You can submit a draft and revise later if you're not done.
Begin submission →