Answer to Question #205310 in Python for Jeevansai Gandham

Question #205310

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.


1
Expert's answer
2021-06-11T05:06:25-0400


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)

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