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 ▸

Generate an array of integers from 0 to 99 and split it into two smaller arrays. Each smaller array will contain half of the original.


Write a basic program to output the lowest of 3 input numbers. (You may omit error checks on your inputs)


What is the difference between & and && operators?


Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.