Some silly coding help

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

Some silly coding help

Postby lmp725 » Sun Apr 21, 2013 6:35 pm

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 Number
s=input("Enter a string for SSN: ").strip()

# Check length
if 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

Postby lmp725 » Sun Apr 21, 2013 6:44 pm

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

Postby micseydel » Mon Apr 22, 2013 1:55 am

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.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 929
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 4 guests