Python program to print odd numbers in a List

In this article, we will learn to find the odd number from the given list and print it in the list format.

How to check whether the given is odd or not?

If a number is not completely divisible by 2, then the given number is odd. 


We find the odd number in a list using 1 method:

  1. Using loop

Input 
: [1,2,3,4,5,6]

Output : [1,3,5]


Using loop

Explanation

  1. First, we initialize a list.
  2. Then we create a new list to store the odds number (named result).
  3. After, that we will run the loop to get all elements of the list one by one.
  4. Then, we will check each element, whether it's completely divisible by the 2 or not.
  5. We will check using the modulus(%) operator.
  6. If the element is not completely divisible by 2, then append to the new list result.
  7. And after all, print the result list.

Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# list
list = [1,2,3,4,5,6,7,8]

# result list
result = []

# iterate all element of list 
for ele in list:
    # check for odd 
    if ele%2!=0:
        result.append(ele) # append the odd number in result list

# print the result 
print(result)

Output

[1, 3, 5, 7]


Conclusion

In this article, we have learned how to create a python program that prints odd numbers in a list using simple methods with the help of a step-by-step explanation.
Next Post Previous Post
No Comment
Add Comment
comment url