Date

Due: Friday, October 7, 11:00 AM

Write a program called credit_card.py to compute if a given number is a valid credit card number.

Credit card numbers have what is called a check digit. This is a simple way of detecting common mis-typings of card numbers. The algorithm is as follows:

  1. Form a sum of every other digit, including the right-most digit; so 5490123456789128 sums to 8+1+8+6+4+2+0+4 = 33
  2. Double each remaining digit, then sum all the digits that creates it; the remaining digits in our example (5 9 1 3 5 7 9 2) double to 10 18 2 6 10 14 18 4, which sums to 1+0+1+8+2+6+1+0+1+4+1+8+4 = 37
  3. Add the two sums above (33+37 = 70)
  4. If the result is a multiple of 10 (i.e., its last digit is 0) then it was a valid credit card number.

An example run might be:

Type a credit card number (just digits): 1
1 is not a valid credit card number

Another run might be:

Type a credit card number (just digits): 240
Yes, 240 is a valid credit card number

Another run might be:

Type a credit card number (just digits): 9548
Yes, 9548 is a valid credit card number

Another run might be:

Type a credit card number (just digits): 5490123456789129
5490123456789129 is not a valid credit card number

Submission: Please submit one .py file named credit_card.py to the POTD submission system at https://archimedes.cs.virginia.edu/cs1110/.