Computer Science homework help. CPSC111 – Introduction to Computing                                     Winter 2020
 
Final ProjectA program using “checksum” to determine if a credit card number is   syntactically valid
 
Name and student #: ___________________________________________________________
 
Name and student #: ___________________________________________________________ 
 
ASSIGNMENT MARK: _____ / 100                                           Due Date: Saturday, April 4th (11:59 PM)
 
For this final project you can work in groups of two (02) to complete it. As always, all your answers should use functions and every function should have a documentation string explaining the purpose of the function. Use the Python template, given to you before, at the top of your program you submit.
 
Do not wait until the last minute to do this final Project in case you run into problems.
Submit your project (one copy per group) to the instructor by email at: drahmalki@gmail.com
 

  • Ensure you have proper program documentation
  • Ensure that each function is documented/explained
  • Submit sample output of your program (via email)
  • Submit the Python source code (via email)
  • Ensure that your project starts with a Python Template

Odds are you have a credit card in your wallet. Though perhaps the bill does not get sent to you yet! That card has a number, both printed on its face and embedded (perhaps with some other data) in the magnetic stripe on back. That number is also stored in a database somewhere, so that when your card is used to buy something, the creditor knows whom to bill. There are a lot of people with credit cards in this world, so those numbers are pretty long:
American Express uses 15-digit numbers, MasterCard uses 16-digit numbers, Visa uses 13- and 16-digit numbers, Discover uses 16, and Diners Club (Carte Blanche) uses 14. And those are decimal numbers (0 through 9), not binary, which means, for instance, that American Express could print as many as  = 1,000,000,000,000,000 unique cards!
 
 

Different Credit cards and their lengths
Credit Card Name Length
AMEX 15
MASTERCARD 16
VISA 13 and 16
DISCOVER 16
DINERS CLUB/ CARTE BLANCHE 14

Actually, credit card numbers have some structure to them. American Express numbers all start with 34 or 37; MasterCard numbers all start with 51, 52, 53, 54, or 55; Visa numbers all start with 4; Discover numbers all start with 6011; and Diners Club (Carte Blanche) numbers start with 300, 301, 302, 303, 304, 305, 36, or 38. But credit card numbers also have a “checksum” built into them, a mathematical relationship between at least one number and others. That checksum enables computers (or humans who like math) to detect typos (e.g., transpositions), if not fraudulent numbers, without having to query a database, which can be slow. (Consider the awkward silence you may have experienced at some point while paying by credit card at a store whose computer uses a dialup modem to verify your card.) Of course, a dishonest mathematician could certainly craft a fake number that nonetheless respects the mathematical constraint, so a database lookup is still necessary for more rigorous checks. So what’s the secret formula? Well, most cards use an algorithm invented by Hans Peter Luhn, a nice fellow from IBM. According to Luhn’s algorithm, you can determine if a credit card number is (syntactically) valid as follows:

  1. Multiply every other digit by 2, starting with the number’s second-to-last digit, and then add those products’ digits together.
  2. Add the sum to the sum of the digits that weren’t multiplied by 2.
  3. If the total’s last digit is 0 (or, put more formally, if the total modulo 10 is congruent to 0), the number is valid!

That’s kind of confusing, so let’s try an example with American Express:
378282246310005
For the sake of discussion, let’s first underline every other digit, starting with the number’s second-to-last digit:
378282246310005
Okay, let’s multiply each of the underlined digits by 2:
7*2 + 2*2 + 2*2 + 4*2 + 3*2 + 0*2 + 0*2
That gives us:
14 + 4 + 4 + 8 + 6 + 0 + 0
Now let’s add those products’ digits (i.e., not the products themselves) together:
1 + 4 + 4 + 4 + 8 + 6 + 0 + 0 = 27
Now let’s add that sum (27) to the sum of the digits that weren’t multiplied by 2:
27 + 3 + 8 + 8 + 2 + 6 + 1 + 0 + 5 = 60
Yup, the last digit in that sum (60) is a 0, so the card is valid!
So, validating credit card numbers isn’t hard, but it does get a bit tedious by hand. Let’s write a program.
Write a program that prompts the user for a credit card number and then reports whether it is a valid American Express, MasterCard, or Visa card number, per the definitions of each’s format herein.
So that I can automate some tests of your code, I ask that your program’s last line of output be
AMEX or
MASTERCARD or
VISA or
DISCOVER or
DINERS CLUB/CARTE BLANCHE or
INVALID
Nothing more, nothing less! For simplicity, you may assume that the user’s input will be entirely numeric (i.e., devoid of hyphens, as might be printed on an actual card).
Here are a few examples (user input is in bold):
Number: 378282246310005
AMEX
Number: 6175230925
INVALID
Test out your program with a whole bunch of inputs, both valid and invalid. (I certainly will!)
Here are a few card numbers that PayPal recommends for testing:
https://developer.paypal.com/docs/payflow/integration-guide/test-transactions/#processors-other-than-paypal
Google (or perhaps a roommate’s wallet) should turn up more.
Submit all your programs as an email attachment (one zipped file) sent to drahmalki@gmail.com
The subject line should be your full name followed by your student number followed by your course number and section.
Using the above described algorithm, create a program that:

  1. Asks the user which type of credit card he/she would like to find the checksum for.
  2. Based on the user’s choice of credit card, asks the user for the n digits of the credit card. [Get the input as a string; it’s easier to work with the string, so don’t convert to an integer.]
  3. Using the user’s input of the n digits, finds the last digit of the sum.
  4. Displays the resulting credit card i.e.; AMEX, MASTERCARD, VISA, or INVALID

 
 
 
 
 
Your program should interact with the user as follows:
Welcome to Checksum of a Credit Card Calculation
————————————————
1. AMEX-8
2. MASTERCARD
3. VISA
4. DISCOVER
5. DINERS CLUB/ CARTE BLANCHE
————————————————
Choose your credit card type: 1
Enter the 15 digits of your credit card: 378282246310005
—————————————
AMEX
 
Another Test:
Welcome to Checksum of a Credit Card Calculation
————————————————
1. AMEX-8
2. MASTERCARD
3. VISA
4. DISCOVER
5. DINERS CLUB/ CARTE BLANCHE
————————————————
Choose your credit card type: 9
Error: 9 is an invalid menu choice.
Try to use good variable names and keep your code as readable as possible along with a good Program Documentation. Coding style is part of the marking scheme.
 
 
 
 
 
Happy Computing!
 
N.B: Next, you are going to make sure you can use the submission properly. This will be how you turn in your assignments electronically. The submission procedure only accepts zip files (NOT rar Files), so you are going to create a “FinalProject_YourFirstName_YourStudentID.zip” file containing all the programs you just wrote as well as this document with your name and student number added to it. To create a “.zip” file, find the directory where the files are saved and select all of them. If you right-click on one of the selected files, you should have the option to create an archive by choosing “Send to” then “Compressed “zipped” Folder”. Rename the created “.zip” file and give it the name FinalProject_YourFirstName_YourStudentID.zip.
10 marks will be deducted if:

  1. the email did not have a full name, a student # and course number and section in the subject field or
  2. the procedure for zipped file is not followed or
  3. Python template and documentation are missing or
  4. This document, with your name and student number on it, is not included with the zipped file or
  1. Screen shots, and sample outputs of all runs

 
A score of zero (0) will be given to everyone whose email is empty.
When you’re done, submit the ZIP file along with screen shots, and sample outputs of all the 6 options to drahmalki@gmail.com
Incomplete projects may be accepted for partial credit but no late work on this project will be accepted after Saturday, April 4th

Computer Science homework help