Hashing Credit Card Program

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Hashing Credit Card Program

Post by LostinCyberia on Mon Aug 27, 2012 12:36 pm
([msg=69044]see Hashing Credit Card Program[/msg])

Hey everyone. I'm still new to python, and programming in general... I'm writing this bit of code that will ask for the user to input a 16 digit card number, and in return scramble the data in some manner... The scrambling isn't the part that is giving me trouble.

I'm using the list feature in python to create an empty list, then have the user input their credit card number, with each digit being a different element in the list. But I can't seem to make that happen. Whenever I then output the numbers, they appear as one long number in the list. I wanted so that each number is shifted individually Here's what I have so far.

#Credit Card Hash

Card_Number = list[] #Setting up the Card_Number variable as an empty list

i = (input( "Welcome. Please enter your 16 digit credit card number here: ")) #Sets the input from the user as i

Card_Number.append(i) # Adds the input from the user to the empty list of Card_Number

if i < 16 :
print ("Sorry, not enough digits provided. Please enter 16 digits")

else i >16:
print ("Sorry, too many digits provided. Please enter 16 digits.")

else i == 16:
print ("Thank you. Please hold...")


Now this is where I have trouble. How do I get the input to the list to be multiple items instead of just one 16 digit item on the list. For example, if they enter 1234567891234567 I want it to be entered into the list as [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7] but when I run this, it becomes just [1234567891234567]. Any help is appreciated
If you see anything else wrong with the if statements let me know, I had some trouble with them as well. Sometimes the code never gets past the first if statement. Even if I enter a number that's over 16 digits. it still gives me the first if.

Thanks!
Remember what the dor-mouse said; Feed your head.
User avatar
LostinCyberia
New User
New User
 
Posts: 13
Joined: Wed Jul 25, 2012 9:42 am
Blog: View Blog (0)


Re: Hashing Credit Card Program

Post by LoGiCaL__ on Mon Aug 27, 2012 7:39 pm
([msg=69046]see Re: Hashing Credit Card Program[/msg])

Not to sure about python. However, if it was c++ I would make it a string. Then you can index each number. Say you wanted to see the third number, you could just reference cardNumber[2]. Instead of making it an empty list just make it a regular string if possible.

Perhaps this will help better explain:

http://home.mindspring.com/~eric_rollins/introProgramming/ch7.html
User avatar
LoGiCaL__
Addict
Addict
 
Posts: 1063
Joined: Sun May 30, 2010 12:33 pm
Blog: View Blog (0)


Re: Hashing Credit Card Program

Post by 0phidian on Mon Aug 27, 2012 8:47 pm
([msg=69047]see Re: Hashing Credit Card Program[/msg])

Pythons input functions return a string by defualt, so you can just use it as an array of characters like LoGICaL__ said.

raw_input() python 2.X
input() python 3.X

If you want to use them as integers when your hashing just typecast them.
Code: Select all
int(Card_Number[0])
User avatar
0phidian
Poster
Poster
 
Posts: 270
Joined: Sat Jun 16, 2012 7:04 pm
Blog: View Blog (0)


Re: Hashing Credit Card Program

Post by LostinCyberia on Mon Aug 27, 2012 10:32 pm
([msg=69048]see Re: Hashing Credit Card Program[/msg])

Ok, got it, just out of curiousity though, there's no way to take a user input and convert it to a list? Thanks for the ideas guys, I'll post again when I finish it
Remember what the dor-mouse said; Feed your head.
User avatar
LostinCyberia
New User
New User
 
Posts: 13
Joined: Wed Jul 25, 2012 9:42 am
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests