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

Related Python Mentoring answers

All answers ▸

What is the outcome of the following code? print(2*[3,4,5])


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


How can you take a list of numbers and add 3 to every number in the list using only one line of code?


How do you write code to implement a recursive fibonacci algorithm?