In this article, we will show you, How to write a Python Program to Count Even and Odd Numbers in an Interval.
Python Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
a=0 b=0 num1=input('Enter a number that begins interval:') num2=input('Enter a number that ends interval:') for i in range(int(num1),int(num2)): if(i%2==0): #even number a+=1 else: b+=1 print('There are {0} numbers that are even'.format(a)) print('There are {0} numbers that are odd'.format(b)) |
Output: