227k views
2 votes
Write a program that finds the number of items above the average of all items. The problem is to read 100 numbers, get the average of these numbers, and find the number of the items greater than the average. To be flexible for handling any number of input, we will let the user enter the number of input, rather than fixing it to 100.

1 Answer

4 votes

Answer:

Written in Python

num = int(input("Items: "))

myitems = []

total = 0

for i in range(0, num):

item = int(input("Number: "))

myitems.append(item)

total = total + item

average = total/num

print("Average: "+str(average))

count = 0

for i in range(0,num):

if myitems[i] > average:

count = count+1

print("There are "+str(count)+" items greater than average")

Step-by-step explanation:

This prompts user for number of items

num = int(input("Items: "))

This creates an empty list

myitems = []

This initializes total to 0

total = 0

The following iteration gets user input for each item and also calculates the total

for i in range(0, num):

item = int(input("Number: "))

myitems.append(item)

total = total + item

This calculates the average

average = total/num

This prints the average

print("Average: "+str(average))

This initializes count to 0

count = 0

The following iteration counts items greater than average

for i in range(0,num):

if myitems[i] > average:

count = count+1

This prints the count of items greater than average

print("There are "+str(count)+" items greater than average")

User Varatis
by
4.8k points