Ajax-loader-large-white
Student Becomes the Teacher
It's Okay to be Average

When teaching a class, it's important to take the students' averages in order to assign grades.

5 / 2
# 2

5.0 / 2
# 2.5

float(5) / 2
# 2.5

The above example is a reminder of how division works in Python.

  1. When you divide an integer by another integer, the result is always an integer (rounded down, if needed).
  2. When you divide a float by an integer, the result is always a float.
  3. To divide two integers and end up with a float, you must first use float() to convert one of the integers to a float.
Instructions

Write a function average that takes a list of numbers and returns the average.

  1. Define a function called average that has one argument, numbers.
  2. Inside that function, call the built-in sum() function with the numbers list as a parameter. Store the result in a variable called total.
  3. Like the example above, use float() to convert total and store the result in total.
  4. Divide total by the length of the numbers list. Use the built-in len() function to calculate that.
  5. Return that result.
?
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

Don't use list as a parameter name because it is a special function in Python. Many people also say you shouldn't use l because it looks too much like a 1.

script.py