Credit card numbers follow a standard system. For example, Visa, MasterCard, and Discover Card all have 16 digits, and the first digit serves to indicate the card brand. All Visa cards start with a 4;...

Credit card numbers follow a standard system. For example, Visa, MasterCard, and Discover Card all have 16 digits, and the first digit serves to indicate the card brand. All Visa cards start with a 4; MasterCard cards always starts with a 5; and Discover cards start with a 6. The first function you will write should be called ‘cardType. Your function should take one input variable, a string representing a card number. The function should return a single string. The string should have one of five values: ‘Visa’, MasterCard’, ‘Discover Card’, ‘Unknown’, or ‘Invalid’. Make sure to watch capitalization and spelling! Your function should first make sure that the input card number has the correct number of digits (16). Remember, the input value is a string, not an int. Your function should return ‘Invalid’ if the card number does not have the correct number of digits and your function should exit. Next, your function should check the first digit of the card number and return the following based on that first digit: return ‘Visa’ if the digit is a 4; return ‘MasterCard’ if the digit is a 5; return ‘Discover’ if the digit is a 6; and return ‘Unknown’ if the card number starts with anything else.

May 25, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here