Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking Social Security
#1
for my project to check social security:

I am wondering if they are correct to run, but seem programming did not do anything

I don't know if it is right:
def main():
    ssn = eval(input("Please enter your Social Security "))

def Check(ssn):
    if len(ssn) == ssn[0:3] and ssn[5:6] and ssn[8:11] == ssn.isdigit():
        if len(ssn) == ssn[4 and 7] == "-":
            print("Your Social Security is valid")

        else:
            print("Your Social Security is invalid")
main()
anyone will help, I will appreciate it, I am still learning to programming in python, soon change to Julia programming

Thank you so much
Reply
#2
First of all, you never call the Check function to test the ssn that is entered. Second, the conditionals in the Check function are completely messed up. len(ssn) should be compared to an integer, not a string, which is what ssn[0:3] is. You put ssn[5:6] between two ands, so all that will be check is whether there is anything in there. And note that ssn[5:6] is only one character. I think what you want is to check each slice of ssn with isdigit, and and together those. Also note that you cannot use and within a slice, as you did with ssn[4 and 7]. Well, you can, but I doubt it's going to give you what you expected.

You really need to go over slicing and conditionals.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
I did call the function, look at

def main():

then I wrote main() at bottom of programming screen "main()"

is it still wrong?

Also, I thought [5:6] is consider 5th string and 6th string to check, then separate the dash in 4 and 7 string to check to see if someone type the dash.
Does it mean, I have to program [5] and [6] or how to make work with numeric symbol?

if you said len is good for integer, then what is name of code to read as string?
Reply
#4
You call the main function, but you don't call the Check function. Nothing in the main function calls the Check function.

Slices in Python are zero indexed, so [0] is the first character, [1] is the second character, and so on. So [5] is the sixth character. If you want the fifth character, you want [4]. The best way to think of it is that four is just before the fifth character (the point in between the fourth and fifth characters). Then [4:5] gives you from just before the fifth character to just before the sixth character, which is just the fifth character. If you want the fifth and sixth characters together, you want [4:6], which is just before the fourth character to just before the seventh character.

As for your len question, what are you trying to read as a string?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
There's no reason to use eval() here. So don't.
Reply
#6
ok, so you have entered an ssn. you have a check() function available. but you did not call that check function. why? is it because of errors there?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
If you want to learn more, download https://pypi.python.org/pypi/python-stdnum/1.5
look at the code for us.ssn: SSN (U.S. Social Security Number)
Even if you are leaving python, it may help in future endeavors.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  social-auth-app-django wheel and dependables "six" metalray 2 2,911 Nov-27-2017, 08:16 AM
Last Post: metalray

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020