You can mail me Contact Me!

Program to check whether the given number is a valid mobile number or not using functions

Program to check whether the given number is a valid mobile number or not using functions

Algorithm:

  1. Define function is_valid_mobile_number that:
    • Takes a string number as input
    • Checks if length is exactly 10 and all characters are digits
    • Checks if first digit is 7, 8, or 9
    • Returns True if both conditions are met, False otherwise
  2. In main program:
    • Get mobile number as input from user
    • Call is_valid_mobile_number function
    • Print appropriate message based on return value

Hello, dear reader! 👋

Thanks for visiting my blog! I’m a student just like you, sharing what I learn to help others with Python programming. I hope my posts are useful for your studies! 😊

If you find this post helpful, please leave a comment—even just a few emojis will make my day! 🐍✨ Your feedback keeps me motivated to create more content for everyone. 🚀

Happy programming!
Abhin Krishna, S01, EB Department, MEC


Pseudocode:

FUNCTION is_valid_mobile_number(number)
    IF length of number = 10 AND number contains only digits THEN
        IF first digit of number IN [7, 8, 9] THEN
            RETURN true
        END IF
    END IF
    RETURN false
END FUNCTION

// Main program
OUTPUT "Enter the mobile number: "
INPUT mobile_number

IF is_valid_mobile_number(mobile_number) THEN
    OUTPUT "The mobile number is valid."
ELSE
    OUTPUT "The mobile number is not valid."
END IF

END
Program:

# Function to check if the given number is a valid mobile number
def is_valid_mobile_number(number):
    # Check if the number contains exactly 10 digits
    if len(number) == 10 and number.isdigit():
        # Check if the first digit is 7, 8, or 9
        if number[0] in ['7', '8', '9']:
            return True
    return False

# Input: Mobile number as a string
mobile_number = input("Enter the mobile number: ")

# Check if the mobile number is valid
if is_valid_mobile_number(mobile_number):
    print("The mobile number is valid.")
else:
    print("The mobile number is not valid.")
Flowchart:
flowchart TD subgraph Function[is_valid_mobile_number Function] A([Start Function]) B[/Input: number/] C{Length = 10 AND\nall digits?} D{First digit is\n7, 8, or 9?} E[Return True] F[Return False] A --> B B --> C C -->|Yes| D C -->|No| F D -->|Yes| E D -->|No| F end subgraph Main[Main Program] M1([Start]) M2[/Input mobile_number/] M3{Call\nis_valid_mobile_number\nfunction} M4[/Print: Number is valid/] M5[/Print: Number is not valid/] M6([End]) M1 --> M2 M2 --> M3 M3 -->|True| M4 M3 -->|False| M5 M4 --> M6 M5 --> M6 end

Important!
If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.

Program to check whether the given number is a valid mobile number or not using functions


1 comment

  1. Comment if you have any doubts
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
Site is Blocked
Sorry! This site is not available in your country.