Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Luhn's algorithm, also known as the modulus 10 or mod 10 algorithm, is a checksum formula used to validate a variety of identification numbers, such
Luhn's algorithm, also known as the modulus 10 or mod 10 algorithm, is a checksum formula used to validate a variety of identification numbers, such as credit card numbers and ID numbers. You will write a program called Luhn.py that asks for an account number and determines whether or not the number is valid using Luhn's algorithm. The steps of the algorithm are given below. 1. Beginning with the second to right-most digit, modify every other digit moving from right to left as follows: o Double the digit's value. o If the resulting number is a two digit number, add the first digit of that value to the second digit, yielding a single digit number. 2. Add the sum of the modified digits to the sum of the digits from the original sequence which were skipped over in step 1. 3. If the resulting sum is evenly divisible by 10, the sequence is valid. If the resulting sum is not divisible by 10, the sequence is not valued. Example In the case of the number 79927398713, we begin with the second to right-most value (the 1), and double every other digit's value from right to left, with the results as indicated in the shaded squares below: 7 1 3 Account number Double every other digit from right to left Sum digits 9 9 2 7 3 9 18 9 4 7 6 9 9 94 7 6 9 8 16 7 7 7 7 7 3 2 2 7 3 The double digit values (16 and 18) are in turned converted to values 7 and 9 respectively by adding their two digits together, resulting in the sequence in the third row above. The sum of 7 + 9 + 9 + 4 + 7 + 6 + 9 + 7 + 7 + 2 + 3 is 70, which is evenly divisible by 10, so this number is valid. Example In the case of the number 12345675, we begin with the second to right-most value (7), and double every other digit's value from right to left, with the results as indicated in the shaded squares below: 2 3 4 6 Account number Double every other digit from right to left Sum digits 1 2 4 2 2 6 6 5 10 1 6 6 7 14 5 5 5 5 2 4 Adding the digits of 10 and 15 give us 1 and 5 respectively, yielding the sequence in the third row. 2+2 +6 +4 + 1 + 6 + 5 + 5 = 31, which is not a multiple of 10, so this account number is not valid. Expected results Your program should positively validate the numbers 79927398713, 49927398716, and 1234567812345670. Your program should mark as not valid the numbers 12345675, 49927398717, and 1234567812345678. As with most well-known algorithms, it's easy to find readymade Python code solutions to this online. Be careful to avoid them until after you've written your own code for the solution
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started