Program to check whether a number is in a given range

In this python function program, we will check whether a number is in a given range.

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 check
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. number to the function.
  4. Check whether the number lies between 1-20 using an if-else statement.
  5. If the number lies between 1-20 then print True else print False.
  6. Take a number through the user as input and pass it to the function while calling the function.
				
					def check(num):
    if num in range(2,20):
        print("True")
    else:
        print("False")    
num1 = int(input("Enter a number: "))
check(num1)
				
			

Output :

				
					Enter a number: 7
True
				
			

Related Articles

reverse a string.

program that takes a list and returns a new list with unique elements of the first list.

Leave a Comment