If it is less than or greater than 8 characters ask for


The last digit of a credit card number is the "check digit" that protects against errors. For simplicity we will use credit cards with just 8 digits instead of 16.  The user will input the 8 digit credit card number as a string and you will convert it to a list using the list() function. You need to validate the length of the string entered. If it is less than or greater than 8 characters, ask for another string. Validate the credit card number that you receive according to the following rules:

  1. Starting from the rightmost digit, form the sum of every other digit - for example, if the credit card number is 43589795 then you form the sum 5 + 7 + 8 + 3 = 23.
  2. Double each of the digits that were not included in the preceding step. Add all digits of the resulting numbers. For example, with the number given above, doubling the digits starting with the next-to-last one, yields 18 18 10 and 8. Adding all the digits in these values results 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27.
  3. Add the sums of the two preceding steps. If the last digit of the result is 0, the number is valid. In the example, 23+ 27 = 50 so the number is valid.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: If it is less than or greater than 8 characters ask for
Reference No:- TGS02508550

Now Priced at $15 (50% Discount)

Recommended (98%)

Rated (4.3/5)