fb pixel

Introduction to Python

  • Profound Academy

    • Status
      • 1
        Input and Output
      • 2
        Variables and Integer Arithmetic
      • 3
        Conditional Operators
      • 4
        Advanced Conditions - Nesting
      • 5
        Types and Variables
      • 6
        Strings
      • 7
        Lists
      • 8
        For Loops
      • 9
        While Loops
      • 10
        continue, break, while...else
      • 11
        String and List methods
      • 12
        Nested Loops
      • 13
        List Comprehension
      • 14
        Tuples and Sets
      • 15
        dict
      • 16
        Functions
      • 17
        Functions 2
      • 18
        Lambda and higher-order functions
      • 19
        Files

  • Is the phone number valid?

    Phone numbers in the United States typically consist of 11 digits:
    • 1-digit country code
    • 3-digit area code
    • 3-digit central office or exchange code
    • 4-digit subscriber number
    A valid example can be: +1 (555) 555-1234.
    So, the phone number should start with a +1, followed by a space and then 3 digits enclosed in parentheses. The last 7 digits are separated by a hyphen after the 3 digits.
    Given a phone number print, The phone is valid if the phone is valid, and Invalid number otherwise.
    Input
    Output
    +1 (555) 555-1234
    The phone is valid
    +1 (5a5) 555-1234
    Invalid number
    +1 (55) 555-1234
    Invalid number
     
    To check your solution you need to sign in
    Sign in to continue