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.
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).
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).
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).")
Comments
Leave a comment