In this program you will test whether a given 16-digit credit card number is valid or not. Here are the steps in your program:

- You will prompt the user to enter a 16-digit credit card number.
- You will read the credit card number in as an
*int*. - You will perform the Luhn's test (outlined below).
- You will then print if the credit card number is valid or not.

- The user enters only digits.
- The user enters exactly 16 digits.

Enter 16-digit credit card number: 1234567891234567 Invalid credit card number

Enter 16-digit credit card number: 4222222222222220 Valid credit card number

**Luhn's Test:** Let us say that the credit card number was made
of the following digits:

** d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16 **

Then the Luhn's algorithm goes as follows:

- Multiply all the odd digits
**d1**,**d3**, …**d15**by 2. - Sum the digits of each product.
- Now add all the even digits
**d2**, …**d16**and the single digit products of the odd digits. - If the final sum is divisible by 10 then the credit card is valid, otherwise it is invalid.

Here are two examples worked out - one is a valid credit card number and the other is an invalid credit card number.

d1 | d2 | d3 | d4 | d5 | d6 | d7 | d8 | d9 | d10 | d11 | d12 | d13 | d14 | d15 | d16 |

4 | 4 | 3 | 2 | 3 | 3 | 3 | 8 | 8 | 4 | 1 | 3 | 8 | 3 | 4 | 3 |

8 | 6 | 6 | 6 | 16 | 2 | 16 | 8 | ||||||||

8 | 6 | 6 | 6 | 7 | 2 | 7 | 8 | ||||||||

8 | 4 | 6 | 2 | 6 | 3 | 6 | 8 | 7 | 4 | 2 | 3 | 7 | 3 | 8 | 3 |

The sum of the digits is **80**. It is divisible by 10
and hence the credit card number is valid.

d1 | d2 | d3 | d4 | d5 | d6 | d7 | d8 | d9 | d10 | d11 | d12 | d13 | d14 | d15 | d16 |

8 | 2 | 7 | 3 | 1 | 2 | 3 | 2 | 7 | 3 | 5 | 1 | 0 | 5 | 6 | 9 |

16 | 14 | 2 | 6 | 14 | 10 | 0 | 12 | ||||||||

7 | 5 | 2 | 6 | 5 | 1 | 0 | 3 | ||||||||

7 | 2 | 5 | 3 | 2 | 2 | 6 | 2 | 5 | 3 | 1 | 1 | 0 | 5 | 3 | 9 |

The sum of the digits is **56**. It is not divisible by 10
and hence the credit card number is invalid.

You must first write the pseudo code version of this algorithm. You
do **NOT** have to submit the pseudo code. Once you have the
pseudo code then you can translate that to Python.

To obtain the last digit of a number use the modulo (%) operator. To remove the last digit of a number divide by 10. Here are snippets of code that will help you with your Python program.

# Prompt the user to enter the credit card number credit_card = int (input ('Enter 16-digit credit card number: ')) # Get digit d16 d16 = credit_card % 10 # Get digit d15 cc = credit_card // 10 d15 = cc % 10 # Multiply odd digit by 2 and sum digits d15 = d15 * 2 sum_d15 = (d15 % 10) + (d15 // 10) # Final validity test for the sum of digits if (sum_digits % 10 == 0): print (...) else: print (...)

The program that you will be writing will be called CreditCard.py. We will be looking at good documentation, and adherence to the coding convention mentioned in class.

- Your variable names will be in lower case.
- You will use meaningful variable names where ever possible.
- You will indent by two spaces.
- All your code must be within
*def main():* - There must be a final call to main().

Your file CreditCard.py will have the following header:

# File: CreditCard.py # Description: # Student Name: # Student UT EID: # Course Name: CS 303E # Unique Number: # Date Created: # Date Last Modified:

Use the
turnin
program to submit your **CreditCard.py** file. The proctors should receive
your work by 11 PM on Monday, 23 Sep 2013. There will be substantial penalties
if you do not adhere to the guidelines. The TA in charge of this
assignment is Lee Thompson (parnell@cs.utexas.edu).

- Your Python program should have the proper header.
- Your code must run before submission.
- You should be submitting your file through the web based
*turnin*program. We will not accept files e-mailed to us. - Here is the Grading Criteria.