Write a function getSSANum() that takes no parameters, but prompts the user to enter a Social Security number, and returns a string representing a formatted version of the first valid number entered by the user. A valid Social Security Number has precisely nine digits and does not contain any other characters. The formatted version that is returned by the function should look like: xxx-xx-xxxx where the x’s represent the digits entered by the user. The user should be repeatedly re-prompted by the function until they enter a string consisting of precisely nine valid digits. Hint: Assign the information from the user as a string and use string functions (len(str) and string method str.isnumeric(str) to determine if the user input is all numeric) to help you determine if what the user entered has the right format. Note the correct solution to this function will involve a while loop (so check the lecture notes 8-2 to refresh on how while loops operate), because the user is entering a string rather than a numeric value. Also do not use a try-except block in the while loop is not helpful. Don’t forget to include the docstring and comments. Copy and paste or screen shot the code and the eight test cases shown below in your submission.
result of code:
>>> getSSANum()
Please enter a nine-digit Social Security number: *********
That is not a valid number. Please try again.
Please enter a nine-digit Social Security number: 888&()280
That is not a valid number. Please try again.
Please enter a nine-digit Social Security number: 12345678
That is not a valid number. Please try again.
Please enter a nine-digit Social Security number: testtest!
That is not a valid number. Please try again.
Please enter a nine-digit Social Security number: 787878789
'787-87-8789'
>>> getSSANum()
Please enter a nine-digit Social Security number: 3.1415926
That is not a valid number. Please try again.
Please enter a nine-digit Social Security number: 314159265
'314-15-9265'
>>> getSSANum()
Please enter a nine-digit Social Security number: 012345678
'012-34-5678'
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images
- Write a function for the Superman ride at Six Flags that determines whether the user is taller than 4'8" so that he or she can ride a roller coasterarrow_forwardCreate a function that determines whether each seat can "see" the front-stage. A number can "see" the front-stage if it is strictly greater than the number before it. Everyone can see the front-stage in the example below: # FRONT STAGE [[1, 2, 3, 2, 1, 1], [2, 4, 4, 3, 2, 2], [5, 5, 5, 5, 4, 4], [6, 6, 7, 6, 5, 5]] # Starting from the left, the 6 > 5 > 2 > 1, so all numbe # 6 > 5 > 4 > 2 - so all numbers can see, etc. Not everyone can see the front-stage in the example below: # FRONT STAGE [[1, 2, 3, 2, 1, 1], [2, 4, 4, 3, 2, 2], [5, 5, 5, 10, 4, 4], [6, 6, 7, 6, 5, 5]] # The 10 is directly in front of the 6 and blocking its varrow_forwardComplete the rotate_text() function that takes 2 parameters, a string data and an integer n. If n is positive, then the function will shift all the characters in data forward by n positions, with characters at the end of the string being moved to the start of the string. If n is 0 then the text remains the same. For example: rotate_text('abcde', rotate_text('abcde', rotate_text('abcde', 1) would return the string 'eabcd' 3) would return the string 'cdeab' 5) would return the string 'abcde' rotate_text('abcde', 6) would return the string 'eabcd' ... and so on. If n is negative, then the function will shift the characters in data backward by n positions, with characters at the start of the string being moved to the end of the string. For example: rotate text('abcde', -1) would return the string 'bcdea'arrow_forward
- Write a Python function named check_email(email_address) takes as input a string (possibly) representing an email address and returns True if the string is a valid CMU email address or returns False otherwise. A valid email address should be of the following form firstname.l@cmu.ac.th, where 'I' is the initial character of a person's which surname. Example inputs jakramate.b@cmu.ac.th. ---> True jakra.boot@cmu.ac.th jakramate.b@cmu.org someone.S@cmu.ac.th ---> False ---> False ---> True Some.L@cmu.ac.th ---> True ThisMakesNoSense ---> False tom.h@gmail.com ---> False narrow_forwardin c programing with User-Defined Functions Remove all non-alphabetic characters Write a program that removes all non-alphabetic characters from the given input. Assume the input string will not exceed 50 characters. Ex: If the input is: -Hello, 1 world$! the output is: Helloworld The program must define and call a function named RemoveNonAlpha that takes two strings as parameters: userString and userStringAlphaOnly. userString is the user specified string from the program input. Function RemoveNonAlpha() then assigns userStringAlphaOnly with the user specified string without any non-alphabetic characters.void RemoveNonAlpha(char userString[], char userStringAlphaOnly[])arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education