6. Problem to differentiate even and odd elements from a list.

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
  1. Take a list as input and create two empty lists with names odd and even.
  2. Use for loop to iterate over each element of the given list.
  3. Use the if statement to check whether the element is even or not during iteration.
  4. If even add that element to the even list, if not add it to the odd list to differentiate even and odd numbers.
  5. 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

minimum and maximum elements

Remove all duplicate elements

Leave a Comment