In this program, we will take a user input as a list and differentiate even and odd elements with the help of the below-given steps.
Differentiate even and odd number in list:
Steps to solve the program
- Take a list as input and create two empty lists with names odd and even.
- Use for loop to iterate over each element of the given list.
- Use the if statement to check whether the element is even or not during iteration.
- If even add that element to the even list, if not add it to the odd list to differentiate even and odd numbers.
- Print both lists to see the output.
#Input list
og_list = [23,11,78,90,34,55]
#creating empty lists
odd = []
even = []
for value in og_list:
if value%2 == 0:
even.append(value)
else:
odd.append(value)
#printing output
print("Even numbers: ", even)
print("Odd numbers: ", odd)
Output :
Even numbers: [78, 90, 34]
Odd numbers: [23, 11, 55]
Related Articles
Python program to remove all duplicate elements from the list.
Python program to print a combination of 2 elements from the list whose sum is 10.
Python program to print squares of all even numbers in a list.
Python program to get common elements from two lists.
Python program to reverse a list with for loop.