Question
AmericanExpress;15;34,37ChinaT-Union;19;31ChinaUnionPay;16,19;62,88Dankort;16;5019DinersClub-CarteBlanche;14;300,301,302,303,304,305DinersClub-International;14;36,38,39DinersClub-USA&Canada;16;54Discover;16,19;6011,622126-622925,644,645,646,647,648,649,65InstaPayment;16;637,638,639JapanCreditBureau(JCB);16;19,3528-3589Maestro;16,19;5018,5020,5038,5893,6304,6759,6761,6762,6763MasterCard;16;51,52,53,54,55,222100-272099RuPay;16;60,6521,6522UATP;15;1Verve;16;506099-506198,650002-650027Visa;13,16,19;4VisaElectron;16;4026,417500,4405,4508,4844,4913,4917 I am trying to read from this file and then check to see when the user enters a credit card number, it would see
AmericanExpress;15;34,37ChinaT-Union;19;31ChinaUnionPay;16,19;62,88Dankort;16;5019DinersClub-CarteBlanche;14;300,301,302,303,304,305DinersClub-International;14;36,38,39DinersClub-USA&Canada;16;54Discover;16,19;6011,622126-622925,644,645,646,647,648,649,65InstaPayment;16;637,638,639JapanCreditBureau(JCB);16;19,3528-3589Maestro;16,19;5018,5020,5038,5893,6304,6759,6761,6762,6763MasterCard;16;51,52,53,54,55,222100-272099RuPay;16;60,6521,6522UATP;15;1Verve;16;506099-506198,650002-650027Visa;13,16,19;4VisaElectron;16;4026,417500,4405,4508,4844,4913,4917
I am trying to read from this file and then check to see when the user enters a credit card number, it would see if it would match a couple of numbers from the third cell and the length from the second cell, in order to get the type in the first cell. It's for a python homework that I am working on. These are the instructions of what I would need to do:
v> We will use the following file to identify credit cards: credit_card_types.ssv (ssv =
semi-colon separated values). This is a plain text file, where the three columns
correspond to the issuing network, length, and issuer identification number (prefix) of the
card.
These are just a few selected example rows from the file:
1: Issuing Network,Length,Issuer Identification Number (Prefix
2: American Express;15;34,37
3: Diners Club - International;14;36,38,39
4: China UnionPay;16,19;62,88
5: MasterCard;16;51,52,53,54,55,222100-272099
Row 1 is the header (not present in the file for convenience of fileIO). A cell is surrounded
by semicolons. A cell may have several numbers separated by commas, or separated by
a hyphen, in which case they represent a range. For example:
?
On row #2, AmEx cards have 15 digits, and they can start with 34 or 37.
?
Row 4 specifies that China UnionPay cards can have 16 or 19 digits and start with
62 or 88.
?
On row 5, we can see that MasterCard has 16-digit card numbers and they can
start with 51, 52, 53, 54, 55, or any sequence between 222100 and 272099,
inclusive.
You will have to read such a file and store the information in an appropriate data structure
to use in your code.
I already have the structure of the code to be split using csv and have ; as a delimiter. I used a for loop to read each line in the file. I also used the split since the second cell (the card length) has more than one length by a comma. Same thing for the third cell (issuer identification). I already created a method to check if the card sequence is valid and the luhn verified. It will be below. The sample output is supposed to be like this:
Please enter a credit card number:5558397375275489Credit card number: 5558397375275489Credit card type: MasterCardLuhn verification: Authentic.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started