76.1k views
4 votes
Write a Python program that will take as input 5 integer values and will output the average of the odd values and the average of the even values that were input. You will need to use if and elif statements to classify each value as odd or even. Be sure to keep track of how many odd values and even values you have, so you can calculate the correct average for each set of values.

User Chere
by
5.4k points

1 Answer

6 votes

Code:

Here is the code. Also screenshot of the code and text file containing the code have been attached here.

This code has been written in Python 3.0

# getting input

lst = [ ]

n = 5

for i in range(0, n):

ele = int(input())

lst.append(ele)

print(lst)

# getting odd numbers and even numbers from list and compute average

odd_sum = 0

even_sum = 0

odd = 0

even = 0

for i in range(0, n):

if lst[i] % 2 == 0:

even_sum = even_sum + lst[i]

even = even + 1

elif lst[i] % 2 > 0:

odd_sum = odd_sum + lst[i]

odd = odd + 1

odd_avg = odd_sum/odd

even_avg = even_sum/even

print("there were",odd,"odd numbers in input")

print("there were",even,"odd numbers in input")

print("average of odd numbers in the list",odd_avg)

print("average of even numbers in the list",even_avg)

Write a Python program that will take as input 5 integer values and will output the-example-1
Write a Python program that will take as input 5 integer values and will output the-example-2
User Depiction
by
5.6k points