51.7k views
4 votes
The mean of a list of numbers is its arithmetic average. The median of a list is its middle value when the values are placed in order. For example, if an ordered list contains 1, 2, 3, 4, 5, 6, 10, 11, and 12, then the mean is 6, and their median is 5. Write an application that allows you to enter nine integers and displays the values, their mean, and their median.

User Ygor
by
5.5k points

1 Answer

6 votes

Answer:

numbers = []

for i in range(9):

number = int(input("Enter an integer: "))

numbers.append(number)

print("The values are ")

for n in numbers:

print(n, end = " ")

print()

total = sum(numbers)

mean = total / len(numbers)

print("Mean is " + str(mean))

numbers.sort()

index = int(len(numbers)//2)

print("Median is " + str(numbers[index]))

Step-by-step explanation:

*The code is in Python.

Create an empty list to hold the numbers

Create a for loop to get 9 integers from the user

Print the numbers using another for loop

Find their total using sum() method

Calculate the mean, divide the total by the length of the list, 9

Sort the list using sort() method

Calculate the index of the median. Use this index to print the median

User Matt Fordham
by
5.2k points