Python function program to get a list of odd numbers from 1 to 100

In this python function program, we will create a function to get a list of odd numbers from 1 to 100.

Odd number:
Odd numbers are those numbers that cannot be divided into two equal parts.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function odd.
  2. Use the def keyword to define the function.
  3. Pass two parameter i.e. starting and ending numbers.
  4. Use for loop with the range function to iterate over values between 1-100.
  5. If a number is an odd number i.e. not divisible by 2 then print the number.
  6. Pass the starting and ending numbers to the function while calling the function.
				
					def odd(lower,upper):
    print("Odd numbers between", lower, "and", upper, "are:")

    for num in range(lower, upper + 1):
        if num%2 != 0:
            print(num,end=" ")
odd(1,100)
				
			

Output :

				
					Odd numbers between 1 and 100 are:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 
49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91
93 95 97 99 
				
			

Related Articles

print a list of prime numbers from 1 to 100.

print and accept login credentials.

Leave a Comment