Articles

program to print odd and even numbers from the list of integers in Python

program to print odd and even numbers from the list of integers in Python


In the python programming guide, we are going to learn

  • program to print odd and even numbers from the list of integers

python program to print odd and even numbers from the list of integers

The python program to print odd and even numbers from the list of integers is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

numbers = [22,11,34,56,78,61,35,91,77,59]

odd_list = list()
even_list = list()
odd_count = 0
even_count = 0

for i in numbers:
    if i % 2 == 0:
        even_list.append(i)
        even_count += 1
    else:
        odd_list.append(i)
        odd_count += 1

print("There are {} odd and {} even elements".format(odd_count,even_count))
print("Odd elements: ", odd_list)
print("Even elements: ", even_list)
        

The output of python program to print odd and even numbers from the list of integers is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
There are 6 odd and 4 even elements
Odd elements:  [11, 61, 35, 91, 77, 59]
Even elements:  [22, 34, 56, 78]

Few important tips about the program

 

1. In the program, from a given list we count the number of odd and even elements and put them in two separate lists accordingly.

2.If a number on being divided by 2 leaves a remainder 0, then the number is even else the number is odd.

 

python program to print odd and even numbers from the list of integers snapshot

program to print odd and even numbers from the list of integers

This wraps up our session on program to print odd and even numbers from the list of integers.


Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Jun 29,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!