Python Program to Print Odd Numbers in a List

This article is created to cover some programs in Python that find and prints all the odd numbers available in a given list by user at run-time. Here are the list of programs:

Print Odd Numbers in List

The question is, write a Python program to find and print all odd numbers available in a list. Here is its answer. This program receives 10 numbers from user as input, then find and print all those numbers as output, that are odd.

n = []
print("Enter 10 Numbers: ")
for i in range(10):
  n.insert(i, int(input()))

print("\nOdd Numbers: ")
for i in range(10):
  if n[i]%2!=0:
    print(n[i])

Here is its sample run. This is the initial output produced by this program:

python print odd numbers in list

Enter any ten numbers say 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 to find and print odd numbers from given list of ten numbers as shown in the snapshot given below:

print odd numbers in list python

Print all Odd Numbers in a List of n Elements

This program allows user to enter any amount of numbers to the list. After receiving inputs, the program will find and prints all the odd numbers from all those numbers that are entered by user at run-time:

n = list()
c = 0
print(end="Enter the Size: ")
nTot = int(input())
print(end="Enter " +str(nTot)+ " Numbers: ")
for i in range(nTot):
  n.append(int(input()))
  if n[i]%2!=0:
    c = 1

if c==0:
  print("\nOdd number is not available in the list!")
else:
  print(end="\nOdd Numbers: ")
  for i in range(nTot):
    if n[i]%2!=0:
      print(end=str(n[i]) +" ")
  print()

Here is its sample run with user input, 5 as size and 5, 6, 7, 8, 9 as five numbers:

python program print odd numbers in list

Here is another sample run with user input 4 as size and 6, 8, 4, 2 as four numbers:

print odd numbers in given list python

Python Online Test


« Previous Program Next Program »