Editor

Fix the Average

Beginner · Fix the bug · from Developing Algorithms: Pseudocode, MOD, and Building Blocks

From the lesson: Developing Algorithms: Pseudocode, MOD, and Building Blocks

An algorithm is a finite set of instructions that accomplishes one specific task, and you can write the same algorithm in plain English, draw it as a flowchart, or type it as code.

Read the lesson

This function should return the average of three test scores, but it gives wrong answers: average_of_three(80, 90, 100) returns about 203.3 instead of 90.0.

Find the order-of-operations bug and fix it.

def average_of_three(a, b, c):
return a + b + c / 3

What Check runs

Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.

RunsExpected output
average_of_three(80, 90, 100)90.0
average_of_three(3, 6, 9)6.0

More Algorithm exercises

All Python exercises · 50 practice problems