93,420 views
35 votes
35 votes
Write a program, which will take 20, inputs from the user and find how many

odd and even numbers are there.

Pseudocode & Python

User Rajeev Akotkar
by
2.5k points

1 Answer

18 votes
18 votes

Answer:

user_input = [int(input()) for i in range(20)]

even = []

odd = []

for i in user_input:

if i%2:

even.append(i)

else:

odd.append(i)

print("odd : ", len(odd), "even : ", len(even))

Step-by-step explanation:

The above code is written in python :

Using a list comprehension we obtain a list of 20 values from the user and store in the variable user_input.

Two empty list are defined, even and odd which is created to store even and odd values.

A for loop is used to evaluate through the numbers in user_input. Even values leave no remainder when Divided by 2 and are appended to the even list while those those leave a raunder are automatically odd values. The elements each list are counted using the len function and are displayed using the print statement.

User Tomocafe
by
2.6k points