In this program, we will add odd numbers to an empty list.
Steps to solve the program
- Take a list as input and create an empty list.
- Use for loop to iterate over each number of the input list.
- If the number is odd then add it to the empty list.
- Print the output.
list1 = [3,8,5,0,2,7]
odd = []
for val in list1:
if val%2 != 0:
odd.append(val)
print("Even numbers: ",odd)
Output :
Even numbers: [3, 5, 7]