In: Computer Science
In the United States, a Social Security number (SSN) is a
nine-digit number that
is a national identification number for taxation purposes. Write a
program that
asks the user for their social security number in DDDDDDDDD format
(where
D is digit). The program first performs a basic check if the number
corresponds
to actual SSN by making sure it has 9 characters in it. If yes, it
creates a string
variable new ssn with SSN in user-friendly DDD − DD − DDDD format
and
prints it. If not, it prints an error message Incorrect SSN
length.
use python
Code:
ssn=input()
if ssn.isnumeric() and len(ssn)==9:
new_ssn=ssn[0:3]+'-'+ssn[3:5]+'-'+ssn[5:]
print("Yes it is an ssn number: ", new_ssn)
else:
print("Incorrect length or invalid ssn number please check your ssn
number")
Code in image:
Output:
Explanation: