For example, if the given range is 2 to 11
odds numbers in the range are 3, 5, 7, 9, 11 then count is 5.
even numbers in the range are 2, 4, 6, 8, 10 then count is 5.
count_odd=0
count_even=0
odd=[]
even=[]
print("Enter the range: ")
start=int(input("From: "))
stop=int(input("To: "))
for i in range(start,stop+1):
if i%2==0:
count_even+=1
even.append(i)
else:
odd.append(i)
count_odd+=1
print("Even numbers in the range are:")
for n in even:
print(n,end="\t")
print()
print("Odd numbers in the range are:")
for n in odd:
print(n,end="\t")
print()
print("The number of even numbers between ",start," and ",stop,"is: ",count_even)
print("The number of odd numbers between ",start," and ",stop,"is: ",count_odd)
Comments
Leave a comment