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
- Create a function check
- Use the def keyword to define the function.
- Pass a parameter i.e. number to the function.
- Check whether the number lies between 1-20 using an if-else statement.
- If the number lies between 1-20 then print True else print False.
- 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