Q:

Python | Program to print Odd and Even numbers from the list of integers

belongs to collection: Python basic programs

0

Logic: To do this, we will simply go through the list and check whether the number is divisible by 2 or not, if it is divisible by 2, then the number is EVEN otherwise it is ODD.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

# Give number of elements present in list
n=int(input())

# list
l= list(map(int,input().strip().split(" ")))

# the number will be odd if on diving the number by 2 
# its remainder is one otherwise number will be even
odd=[]
even=[]

for i in l:
    if(i%2!=0):
        odd.append(i)
    else:
        even.append(i)

print("list of odd number is:",odd)
print("list of even number is:",even)

Output

Python program to print EVEN and ODD

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Program to print Palindrome numbers from ... >>
<< Python | Declare any variable without assigning an...