CBSE Class 11 Computer Science Question 62 of 82

Lists in Python — Question 27

Back to all questions
27
Question

Question 22

Write a program to calculate mean of a given list of numbers.

Solution
numbers = eval(input("Enter a list: "))
if len(numbers) == 0:
    print("List is empty, cannot calculate mean.")
else:
    total = sum(numbers)
    n = len(numbers)
    mean = total / n
    print("Mean of the numbers:", mean)
Output
Enter a list: [10, 30, 25, 34, 45, 98]
Mean of the numbers: 40.333333333333336
Answer