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
- Create a function odd.
- Use the def keyword to define the function.
- Pass two parameter i.e. starting and ending numbers.
- Use for loop with the range function to iterate over values between 1-100.
- If a number is an odd number i.e. not divisible by 2 then print the number.
- 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
Python function program to print and accept login credentials.
Python function program to get the addition with the return statement.
Python function program to create a Fruitshop Management system.
Python function program to check whether the given year is a leap year.
Python function program to reverse an integer.
Python function program to create a library management system.