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 ▸

Create a program that takes in two numbers and returns the highest of the two


Create an rock, paper, scissors game. The user should input one option, and the computer should play randomly.


Describe both For-loops and While-loops and explain how you can simulate the effect of a for loop with a while loop with an example.


What built-in types does python provide?