## Some silly coding help

This is the place for queries that don't fit in any of the other categories.

### Some silly coding help

OK so I have to write a code that prompts a user to enter a SSN and it states it back saying if it is valid or invalid ssn.

Code: Select all
`# Prompt user to enter a Social Security Numbers=input("Enter a string for SSN: ").strip()# Check lengthif len(s) != 11    print("inValidSSN")if isValidSSN(s):    print("ValidSSN")else:    d = a[0:3], up = [3]    d1 = b[4:6], up1 = [6]    d2 = c[7:11], up2[]    d.isdigit() and up == '-' and if d1.isdigit() and up == '-':    print("Valid SSN")    else:    print(:InValidSSN")`

This is the error I get back.

Traceback (most recent call last):
File "<string>", line 5, in <fragment>
Syntax Error: if len(s) != 11: <string>, line 516

I am not sure what if off on line 5.
lmp725

Posts: 13
Joined: Sun Apr 14, 2013 6:27 pm

### Re: Some silly coding help

OK so I tweeked it a lot. here is what I have.

Code: Select all
`s = input("Enter a string for SSN: ").strip() if len(s) == 11:    print("Valid SSN")else:        d = s[0:3]    up = [3]    d1 = s[4:6]    up1 = [6]    d2 = s[7:11]                if d.isdigit() and up == [3] and d1.isdigit() and up == [6]:        print("Invalid SSN")    else:        print("Valid SSN")`

It is not working because I have to add something that would state invalid ssn if someone used anything but a number in. How would I add that to the code?
lmp725

Posts: 13
Joined: Sun Apr 14, 2013 6:27 pm

### Re: Some silly coding help

You should be posting runnable code along with a traceback from that snippet. Don't post a traceback from a 500+ line script. Don't expect us to type example input to your program.

The more recent code you posted has you assigned up to a list, then you check that list later. It has nothing to do with user input.\

I believe you can really simplify this too by simply using str.split() and then checking the values from it.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Return to General Coding Help

### Who is online

Users browsing this forum: No registered users and 3 guests