Question: This program reads an input file containing credit card information and determines if the card numbers and expiration dates are valid. A card number consists

This program reads an input file containing credit card information and determines if the card numbers and expiration
dates are valid. A card number consists of digits 0 through 9 and uppercase letters and is valid if it follows these rules:
Has a length of exactly 12 characters.
The first character is the letter A,C, or E.
The sum of the digits, when divided by 5, leaves a remainder of 0(i.e., sum %5 equals 0).
A card is considered expired if its expiration date is earlier than the current date (i.e., month and year). If the cards
year is earlier than the current year, the card is no longer valid. If the card's year is the same as the current year, the
months are compared. The card is considered invalid if its month is earlier than the current month.
Overall, a card is considered Valid if both the credit card number and expiration date are valid.
The program will read the credit card information from an input file. As it reads a record, determine if the card
number is valid and if the card expiration date is valid. The program also counts the number of records in the input
file, and how many of those cards were valid and invalid.
Input: All input is in a file named CardNumbers.py. It contains a series of records, and each record has 2 pieces of
data:
Credit card number (a string of uppercase letters and digits)
Expiration date (string that uses two digits for the month and four digits for the year, separated by a forward
slash : MM/YYYY)
The input file is of unknown length and ends when the card number is ### (i.e., the sentinel value ).
Objectives:
File input, functions, selection, looping structures, formatted output
There is only one day (24-hours) late
submission allowed on this assignment.
Formatted Output: The output table must display the credit card number, expiration date, card number length,
whether the length is valid, the first character, whether the first character is valid, sum of the digits, whether the sum is
valid, whether the card number is valid, whether the expiration date is valid, and an overall decision if the credit card is
valid (see sample run). The symbol + is used to represent a valid output; a is used to indicate an invalid output. The
overall decision indicating if the card is valid or invalid are the strings VALID and INVALID. All data must be
neatly aligned, including final counts should also be aligned.
Credit card numbers will not exceed 14-digits; integer data will not exceed 3-digits.
Function Requirements:
All code must be contained inside functions. In addition to the main() function, you must also write the following
programmer-defined function using the specifications given:
A function to print the table header
This function prints the tables header labels: Card Number, Exp Date, Length, First (character), Sum,
Number, Date, and Card, etc..
o Input parameters (0):
There are no input parameters.
o Return values (0):
The function prints to the screen and does not return any values (void function).
A function to sum the digits in the card number.
This function iterates through each character in the card number, and if the character is a digit, it adds its
value to the sum.
o Input parameters (1):
Credit card number (string)
o Return values (1):
The sum of the digits (an int)
A function to check if the expiration date is valid.
A date is deemed expired if the card's year is earlier than the current year. If the card's year is the same as
the current year, the months are compared. The card is considered expired if its month is earlier than the
current month.
To get the current date (month and year), import the datetime library and include the following code in
your function:
today = datetime.date.today()
currentYear = today.year #current month and year
currentMonth = today.month #stored as integers
o Input parameters (1):
Credit cards expiration date (string in the format MM/YYYY)
o Return values (1):
A string indicating if the expiration date is valid or invalid. The sample runs return + for a
valid date and - for an invalid date.

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!