Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Credit card numbers follow a standard system. For example, Visa,MasterCard, and Discover Card all have 16 digits, and the firstdigit serves to indicate the card

Credit card numbers follow a standard system. For example, Visa,MasterCard, and Discover Card all have 16 digits, and the firstdigit serves to indicate the card brand. All Visa cards start witha 4; MasterCard cards always starts with a 5; and Discover cardsstart with a 6.

The first function you will write should be called ‘cardType.Your function should take one input variable, astring representing a card number.

The function should return a single string. Thestring should have one of five values: ‘Visa’, MasterCard’,‘Discover Card’, ‘Unknown’, or ‘Invalid’. Make sure to watchcapitalization and spelling!

Your function should first make sure that the input card numberhas the correct number of digits (16). Remember, the input value isa string, not an int. Your function should return ‘Invalid’ if thecard number does not have the correct number of digits and yourfunction should exit. Next, your function should check the firstdigit of the card number and return the following based on thatfirst 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; andreturn ‘Unknown’ if the card number starts with anything else.

T esting:

cardType(‘2845682912345’)

Should return:

Invalid cardType(‘4124836490234794’) Should return:
Visa

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

Avoid evasiveness. Be direct with your answers when possible.

Answered: 1 week ago

Question

Propose a reasonable mechanism for the following reaction. OH

Answered: 1 week ago