Step 2 of 2

Tidy a function

Tidy a function

Someone left this function in a state. Make it match the target shown in the panel below the prose, exactly — same lines, same order, same indentation of four spaces per level.

What’s wrong with the buffer, top to bottom:

  • a leftover print line has to go
  • count is computed before the loop instead of after it
  • the body of the loop was split across two lines and lost its indent
  • LEN should be lowercase
  • the result should round to two places, not one

If a step has you stuck, lesson 4 covers selecting and deleting, lesson 6 moving lines through registers, and lesson 8 joining, indenting, changing case, and adjusting numbers. Undo is always there if a change goes wrong.

  1. Make the file match the target
Make the file match the target
def average(scores):
    total = 0
    for score in scores:
        total = total + score
    count = len(scores)
    return round(total / count, 2)

Last one — goal check runs when it's done

Loading editor…