In this python function program, we will get a valid mobile number using a function. A mobile number should have only 10 integers to be a valid mobile number.
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 mobile_number.
- Use the def keyword to define the function.
- Take the mobile number as input through the user.
- If the length of the number is 10 then it is a valid mobile number if not then it is not a valid number.
- Use an if-else statement for this purpose.
- Print the respective output.
- Call the function to get the result.
def mobile_number():
num = int(input("Enter phone number: "))
if len(str(num)) == 10:
print("It is a valid phone number")
else:
print("It is not a valid phone number")
mobile_number()
Output :
Enter phone number: 24568526
It is not a valid phone number
Related Articles
Python function program to convert an integer to its word format.
Python function program to get all permutations from a string.
Python function program to add two numbers.
Python function program to print the input string 10 times.
Python function program to print a table of a given number.
Python function program to find the maximum of three numbers.