Question

Write a function “ssnChecker” that takes a string “s” and validates if the string is in...

Write a function “ssnChecker” that takes a string “s” and validates if the string is in a valid social security number format (999-99-9999). The function must return a Boolean value (True or False).

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def ssnChecker(s):
    if len(s)==13:
        for i in range(len(s)):
            if i==0:
                if s[i]!="(":
                    return False
            elif (i>=1 and i<=3) or (i>=5 and i<=6) or (i>=8 and i<=11):
                if not (s[i]>='0' and s[i]<='9'):
                    return False
            elif i==12:
                if s[i]!=")":
                    return False
            else:
                if s[i]!="-":
                    return False
        return True
    else:
        return False

# Testing
print(ssnChecker("(999-99-9999)"))
print(ssnChecker("(999-99-999"))

Add a comment
Know the answer?
Add Answer to:
Write a function “ssnChecker” that takes a string “s” and validates if the string is in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function is_mirror(s) that takes as input a string s and returns True if s...

    Write a function is_mirror(s) that takes as input a string s and returns True if s is a mirrored string (i.e., a string that could have been produced by your mirror function) and False otherwise. Examples: >>> is_mirror('baconnocab') result: True >>> is_mirror('baconnoca') result: False Warning Your function should return a boolean value – either True or False, without any quotes around them. If you see quotes around the result when you make the calls above from the console, you must...

  • C++ Programming: Write a function that takes in a C++-style string s (from #include ), as...

    C++ Programming: Write a function that takes in a C++-style string s (from #include ), as well as an integer n, and then returns true if any substring of length n in s repeats itself, and false otherwise. For example, if s is "toe-to-toe" and n is 3, then the function would return true since "toe" occurs twice within s. However, if n were 4, the function would return false. As a second example, if s is "singing" and n...

  • Write a function named "find_key" that takes a key-value store as a parameter with strings as...

    Write a function named "find_key" that takes a key-value store as a parameter with strings as keys and integers as values. The function returns a boolean representing true if the string "focus" is in the input as a key, false otherwise(javascript)

  • Write the function deep_contains. It takes as input a number and a list. That list might...

    Write the function deep_contains. It takes as input a number and a list. That list might contain lists as elements, and those lists might contain lists, etc. The deep_contains' function should return a Boolean indicating whether the number is contained inputted list, or a sublist of it, or a sublist of that, and so forth. For example: deep_contains (3, (1,3,5]) returns True deep_contains(3, 11, [3,5]]) returns True deep_contains (3, 1, [[3,4],5),6]) returns True deep_contains (2, (1,3,5]) returns False This function...

  • CODIO python problem Write a function isRed() that accepts a string parameter and looks for the...

    CODIO python problem Write a function isRed() that accepts a string parameter and looks for the presence of the word ‘red’ in the string. If it is found, return boolean True otherwise False. Finally output the result of calling the function with the value in text.

  • Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true...

    Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true if it is a nesting of zero or more pairs of parentheses, e.g. "((()))" should return True ; "()()" or "(()))" should return False . Use recursion for this problem. nestedParens :: String -> Bool

  • Define a function in pycharm (isValid) that takes a password as a parameter and returns true...

    Define a function in pycharm (isValid) that takes a password as a parameter and returns true if the password is valid or false if the password is invalid. A valid password must be at least 8 characters long and contains $, _, or @. Invoke the function and print valid or invalid according to the returned Boolean value. Sample, if (isValid(password) == True): print(“Valid”) Or, result = isValid(password) If (result): print(“invalid”)

  • 4. Write a C function int str2int(char *s) that takes string s as parameter and return...

    4. Write a C function int str2int(char *s) that takes string s as parameter and return the integer that s represents. For example, if string s is 123", then the function return integer 123.

  • Write a method in java named isValidEmail that takes a string as input parameter, and returns...

    Write a method in java named isValidEmail that takes a string as input parameter, and returns true if that string represents a valid email address, or false otherwise. An email address is considered valid if it follows this format “[email protected]”, where:  user123 represents a sequence of word characters (i.e., letters, digits, or underscore) whose length is between 1 and 10 (inclusive), but the first character must be a letter  domain represents a sequence of alphanumeric characters (i.e., letters...

  • Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String a...

    Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String argument. The method will return a new String by removing the logest segment that contains consequtively repeating characters. public static void main(String []args){ String s=”1111222223333311111111444455552222”; String res= removeLongestRepeatingSegment(s); will return “11112222233333444455552222” } public static String removeLongestRepeatingSegment(String s){ --------------- Q2)15p)Given a list of objects stored (in ascending order) in a sorted linked list, implement member method which performs search as efficiently as possible for an object based on a key....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT