Program to get a valid mobile number using a function

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
  1. Create a function mobile_number.
  2. Use the def keyword to define the function.
  3. Take the mobile number as input through the user.
  4. If the length of the number is 10 then it is a valid mobile number if not then it is not a valid number.
  5. Use an if-else statement for this purpose.
  6. Print the respective output.
  7. 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

get the length of the last word in a string.

convert an integer to its word format.

Leave a Comment