Write a program that prompts the user to enter a Social Security number in the format ddd-dd-dddd, where d is a digit. The program displays Valid SSN for a correct Social Security number or Invalid SSN otherwise.

Respuesta :

ssn = input("Enter a valid Social Security number: ")

dashes = 0

nums = 0

message = "Invalid SSN"

if len(ssn) == 11:

   for x in ssn:

       if x.isdigit():

           nums += 1

       elif x == "-":

           dashes += 1

if nums == 9 and dashes == 2:

   message = "Valid SSN"

print(message)

I wrote my code in python 3.8. I hope this helps!