Answer to Question #280321 in Python for hayden

Question #280321

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. Continue doing this as many times as the user indicated. Once the loop ends, output how many even numbers were entered and how many odd numbers were entered.

Sample Run 1

How many numbers do you need to check? 5
Enter number: 20
20 is an even number.
Enter number: 33
33 is an odd number.
Enter number: 4
4 is an even number.
Enter number: 77
77 is an odd number.
Enter number: 8
8 is an even number.
You entered 3 even number(s).
You entered 2 odd number(s).

Sample Run 2

How many numbers do you need to check? 3
Enter number: 10
10 is an even number.
Enter number: 3
3 is an odd number.
Enter number: 400
400 is an even number.
You entered 2 even number(s).
You entered 1 odd number(s).






1
Expert's answer
2021-12-16T04:45:19-0500
totalNumbers=int(input("How many numbers do you need to check? "))
evenNumber=0
oddNumber=0
for n in range(0,totalNumbers):
    number=int(input("Enter number: "))
    if number%2==0:
        print(f"{number} is an even number.")
        evenNumber+=1
    else:
        print(f"{number} is an odd number.")
        oddNumber+=1
print(f"You entered {evenNumber} even number(s).")
print(f"You entered {oddNumber} odd number(s).")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS