Here, we are going to actualize a python program that will print the list in the wake of expelling ODD numbers.
Given a list, and we need to print the list in the wake of expelling the ODD numbers in Python.
Example:
Input:
list = [11, 22, 33, 44, 55]
Output:
list after removing ODD numbers
list = [22, 44]
Rationale:
- Navigate each number in the list by utilizing for…in circle.
- Check the condition for example checks number is separable by 2 or not – to check ODD, the number must not be distinguishable by 2.
- On the off chance that number isn’t distinct by 2 for example ODD number from the list, use list.remove() strategy.
Program:
# list with EVEN and ODD number
list = [11, 22, 33, 44, 55]
# print original list
print "Original list:"
print list
# loop to traverse each element in the list
# and, remove elements
# which are ODD (not divisible by 2)
for i in list:
if(i%2 != 0):
list.remove(i)
# print list after removing ODD elements
print "list after removing ODD numbers:"
print list
Output:
Original list:
[11, 22, 33, 44, 55]
list after removing ODD numbers:
[22, 44]
Hi , I am sabaresan D from chennai Ece Department in s.a.engineering college , I am also very interest python to do code but i don’t know where i going to start ..can you help me pls?.
dsabaresan@gamil.com this is my mail id..
Hi, please follow our python tutorials step by step for learning python from scratch.