Computer Science
Write a program to calculate the mean of a given list of numbers.
Answer
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
Related Questions
Why are lists called a mutable data type?
What is the difference between insert() and append() methods of a list?
Write a program to calculate the minimum element of a given list of numbers.
Write a code to calculate and display total marks and percentage of a student from a given list storing the marks of a student.