Question: Computer science help: checkCreditCard in Python 1.Write a function that takes, as an argument, either a 16-digit string or positive integer, n, and does the
Computer science help: checkCreditCard in Python
1.Write a function that takes, as an argument, either a 16-digit string or positive integer, n, and does the following, in this order:
Verifies that it consists of only digits (if it fails, return the string not digits)
Verifies that it consists of 16 digits (if it fails, return the string wrong length)
If n is a string, it converts n to an integer
Creates a list, myList, where each element is a single digit in n, using the function
intToList(n) created in Problem 3
Multiplies the elements in the even indices of myList by 2, and any products that
produce a two-digit number are replaced by the sum of the digits using the function addDigits(n) created in Problem 2 (for example, if an entry at an even index is 8, when multiplied by 2 will equal 16...replace this value with 7 (the sum of the digits)
Compute the sum of all of the single digits in myList. If the sum is equal to 0 modulo 10, the original value, n, is a valid number (return True). Otherwise, return the string invalid entry.
Name this function checkCreditCard(n)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
