118k views
4 votes
Write a program that repeatedly takes integers from the user as long as he

wants to input. The program then, shows a summary of the inputs. The summary
should include: 1) minimum of the inputs, 2) maximum of the inputs, 3) total Even
inputs , 4) total Odd inputs, 5) Average of Even numbers, 6) Average of Odd
numbers, and 7) the total Average

User Kotekzot
by
5.0k points

1 Answer

1 vote

Answer:

Written in Python:

evens = 0

odds = 0

oddtotal = 0

eventotal = 0

total = 0

mylst = []

tryag = "Y"

while tryag == "Y" or tryag == "y":

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

mylst.append(num)

tryag = input("Another Input (Y/y): ")

mylst.sort()

print("Minimum: "+str(mylst[0]))

print("Maximum: "+str(mylst[-1]))

for i in mylst:

total = total + i

if i%2 == 0:

evens = evens + 1

eventotal = eventotal + i

else:

odds = odds + 1

oddtotal = oddtotal + i

print("Evens: "+str(evens))

print("Odds: "+str(odds))

print("Even Average: "+str(eventotal/evens))

print("Odd Average: "+str(oddtotal/odds))

print("Total Average: "+str(total/(evens+odds)))

Step-by-step explanation:

The following lines initializes useful variables to 0

evens = 0

odds = 0

oddtotal = 0

eventotal = 0

total = 0

This declares an empty list

mylst = []

tryag = "Y"

This is repeated until user stops the loop by entering strings other than y or Y

while tryag == "Y" or tryag == "y":

This prompts user for input

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

User input is appended to the list

mylst.append(num)

This prompts user to try again the loop

tryag = input("Another Input (Y/y): ")

This sorts the list from small to large

mylst.sort()

This prints 1. The minimum

print("Minimum: "+str(mylst[0]))

This prints 2. The maximum

print("Maximum: "+str(mylst[-1]))

The following iterates through the list

for i in mylst:

This calculates the total

total = total + i

This checks for even entry

if i%2 == 0:

This counts the number of even entries

evens = evens + 1

This sums the even entries

eventotal = eventotal + i

else:

This counts the number of odd entries

odds = odds + 1

This sums the odd entries

oddtotal = oddtotal + i

This prints 3. Sum of Even entries

print("Evens: "+str(evens))

This prints 4. Sum of Odd entries

print("Odds: "+str(odds))

This prints 5. Average of Even entries

print("Even Average: "+str(eventotal/evens))

This prints 6. Average of Odd entries

print("Odd Average: "+str(oddtotal/odds))

This prints 7. Total Average

print("Total Average: "+str(total/(evens+odds)))

User Alex Smolov
by
4.8k points