Question: PYTHON FUNCTION: PLEASE SERIOUS PROGRAMER AND FOLLOW INSTRUCTIONS . THANKS!! Program 2 (20 pts) Fall 2016 Credit Card Number Validation: The Luhn check or the

PYTHON FUNCTION: PLEASE SERIOUS PROGRAMER AND FOLLOW INSTRUCTIONS . THANKS!!

Program 2 (20 pts) Fall 2016 Credit Card Number Validation: The Luhn check or the Mod 10 check

In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered or scanned correctly. To ensure validity:

Check to see that the number has 13-16 digits

For certain companies, must start with a particular number:

Visa cards: must start with 4

Mastercard: must start with 5

American Express: must start with 37

Discover: must start with 6

Going from RIGHT to LEFT, double every second digit. If doubling a digit results in a two-digit number, add up the two digits to get a single-digit number.

Then ADD all of these single-digit numbers together sumSecondDigits.

Next, going from RIGHT to LEFT, add all digits in the ODD places sumOddPlaces.

Add the sumSecondDigits to the sumOddPlaces. If the result is divisible by 10, the card number is valid. Otherwise, it is invalid.

Write a function called isValidCreditCard that reads accepts a string and returns True if the string represents a valid credit card number and False if it is invalid.

NOTE: the function MUST call other functions to complete its work. You should create at LEAST the following functions:

A function that accepts a string and returns the sum of the digits in the even places doubled

A function that accepts a string and returns the sum of the digits in odd places

A function that accepts a string and returns the Prefix as a string (Visa, MC, Discover, AmEx).

Others as you see fit

Step 2: Create a list of sample credit card numbers and call your function, printing the number and a message indicating if the number was valid or not. Here are some ideas about what to test:

Too long

Too short

Valid 13-16 digit entry

First character is a letter

Beginning characters not valid (starts with letter, starts with # other than 4, 5, 6 or 37)

Sum of sums not evenly divisible by 10

Valid Discover # 6312345678901

Valid Visa # 4388576018410707

Valid AmEx #

Valid Mastercard #

=========================================================================================

Example1:

CardNumber: 4388576018402626 Length: 16 Prefix: Visa sumDblEvenPlace: 37

2*2 = 4, 2*2=4, 4*2 = 8, 1*2 = 2, 6*2 = 12 two digits, so add them and get 1+2 =3, 5*2 = 10 two digits, so add them and get 1+ 0 =1, 8*2 = 16 two digits, so add them and get 1+6 =7, 4*2 = 8 Sum: (4 + 4 + 8 + 2 + 3 + 1 + 7 +8) 37

sumOddPlace: 38 ( 6+6+0+8+0+7+8+3) Valid?: No

Example2:

CardNumber: 4388576018410707 Length: 16 Prefix: Visa sumDblEvenPlace: 29 ( 0 + 0+ 8 + 2 + 3 + 1 + 7 + 8 = 29) sumOddPlace: 41 7 + 7 + 1 + 8 + 0 + 7 + 8 + 3 = 41 Valid: Yes (29 + 41 = 70 which is evenly divisible by 10)

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 Databases Questions!