even_count = 0
odd_count = 0
for i in range(10):
num = int(input(f"Enter number {i+1}: "))
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
print(f"Total even numbers: {even_count}")
print(f"Total odd numbers: {odd_count}")
#source code --> clcoding.com
Code Explanation:
Initialize Counters:
even_count = 0
odd_count = 0
These variables keep track of the number of even and odd numbers.
Loop to Take 10 Inputs:
for i in range(10):
num = int(input(f"Enter number {i+1}: "))
The loop runs 10 times, prompting the user to enter a number each time.
Check for Even or Odd:
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
If num is divisible by 2, it's even, so even_count is incremented.
Otherwise, it's odd, so odd_count is incremented.
Display the Final Count:
print(f"Total even numbers: {even_count}")
print(f"Total odd numbers: {odd_count}")
This prints the total count of even and odd numbers.
0 Comments:
Post a Comment