Write a Python program to select the odd number of a list


This program is using a for loop to iterate through the list of integers called "a". For each integer "i" in "a", it is checking if the remainder of i divided by 2 is equal to 1 (if i is odd) using the modulus operator %. If the condition is true, it means the current integer is odd, so it is appending that integer to a new list called "odd_num". After the for loop is finished, the program is printing the final list "odd_num" which contains only the odd numbers from the original list "a".

Source Code

a=[1,2,4,3,6,7,5,8,9,7,8,9,10]
odd_num=[]
for i in a:
	if(i%2==1):
		#print(i)
		odd_num.append(i)
print(odd_num)

Output

[1, 3, 7, 5, 9, 7, 9]

Example Programs