Question: Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type of credit card he/she would like to find the

Using the above described algorithm, create a program that: (IN PYTHON)

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

According to Luhns algorithm, you can determine if a credit card number is (syntactically) valid as follows:

1. Multiply every other digit by 2, starting with the numbers second-to-last digit, and then add those products digits together.

2. Add the sum to the sum of the digits that werent multiplied by 2.

3. If the totals last digit is 0 (or, put more formally, if the total modulo 10 is congruent to 0), the number is valid! Thats kind of confusing, so lets try an example with American Express: 378282246310005

lets first underline every other digit, starting with the numbers second-to-last digit: 378282246310005

lets 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 lets add those products digits (i.e., not the products themselves) together: 1 + 4 + 4 + 4 + 8 + 6 + 0 + 0 = 27

Now lets add that sum (27) to the sum of the digits that werent 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 isnt hard, but it does get a bit tedious by hand.

Lets 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 eachs format herein.

your programs last line of output be AMEX or MASTERCARD or VISA or DISCOVER or DINERS CLUB/CARTE BLANCHE or INVALID EXAMPLES Here are a few examples (user input is in bold):

Number: 378282246310005

AMEX

Number: 6175230925

INVALID

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!