70.1k views
5 votes
Write a program that will ask a user for how many numbers they would like to check. Then, using a for loop, prompt the user for a number, and output if that number is even or odd.

Benchmark:

Prompt the user to answer the question, "How many numbers do you need to check?"

Create and initialize two count variables - one for odd and one for even.

Based on the previous input, create a for loop that will run that exact number of times.

Prompt the user to "Enter number: "

If that number is even, output "[number] is an even number."

Update the even count variable.

Or else if the number is odd, output "[number] is an odd number."

Update the odd count variable.

Output "You entered [number] even number(s)."

Output "You entered [number] odd number(s)."

Please write the code in the Python language.

1 Answer

2 votes

Answer:

c = int(input("How many numbers do you need to check? "))

o = 0

e = 0

for i in range (c):

i = int(input("Enter number: "))

r = i % 2

if (r == 1):

print (str(i) + " is an odd number.")

o=o+1

if (r==0):

print(str(i) + " is an even number.")

e=e+1

print("You entered " + str(e) + " even number(s).")

print("You entered " + str(o) + " odd number(s).")

Step-by-step explanation:

User Daverocks
by
8.4k points