Write a function that takes a list of numbers as input, and outputs the average of the numbers. The function should catch any errors.

def average(numberList):  try:    total=0    length=len(numberList) #len finds the length of a list    for i in range(length): #adds up the numbers      total=total+numberList[i]    return total/length #returns the final total  except: #is only executed if an error occurs    return "error"

JP
Answered by Jonathan P. Python tutor

1902 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

[Student query] Why do we import libraries/modules such as Numpy and Matplotlib into Python?


Write a short program to print all the even numbers 1 to 100


Write a recursive function to return the nth Fibonacci number in Python


Why are negative indexes used?


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2025 by IXL Learning