Python Starting with the right-most digit and moving to the left, determine the sum of every alternating digit. For the credit card “4833 1200 3412 3456”, we would sum 6 + 4 + 2 + 4 + 0 + 2 + 3 + 8 = 29. Double each of the digits not included in the previous step and then add all of the digits of the resulting numbers. For example, with the number given in step 1, doubling the digits, starting with the second-to-last one, yields 10 6 2 6 0 2 6 8. Adding all of the digits in these values yields 1 + 0 + 6 + 2 + 6 + 0 + 2 + 6 + 8 = 31. Add the sums of the two preceding steps. If the last digit of the result is zero (i.e., it is divisible by 10), the number is valid. In our case, 29 + 31 = 60, so the credit card number is valid. Example Execution #1 Input a credit card number to check its validity. NUMBER> 6 0   1 1 624 9 8671 7892 7 8 9 9 Sum 1: 46 Sum 2: 56 Overall Sum: 102 The credit card number is invalid. OUTPUT Invalid The correct check digit is 7. OUTPUT 7   Example Execution #2 Input a credit card number to check its validity. NUMBER> 5456 6874 5689 3405 Sum 1: 46 Sum 2: 24 Overall Sum: 70 The credit card number is valid. OUTPUT Valid   Example Execution #3 Input a credit card number to check its validity. NUMBER> 4543   656 7 3323 6761 Sum 1: 34 Sum 2: 38 Overall Sum: 72 The credit card number is invalid. OUTPUT Invalid The correct check digit is 9. OUTPUT 9

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python

  1. Starting with the right-most digit and moving to the left, determine the sum of every alternating digit. For the credit card “4833 1200 3412 3456”, we would sum 6 + 4 + 2 + 4 + 0 + 2 + 3 + 8 = 29.

  2. Double each of the digits not included in the previous step and then add all of the digits of the resulting numbers. For example, with the number given in step 1, doubling the digits, starting with the second-to-last one, yields 10 6 2 6 0 2 6 8. Adding all of the digits in these values yields 1 + 0 + 6 + 2 + 6 + 0 + 2 + 6 + 8 = 31.

  3. Add the sums of the two preceding steps. If the last digit of the result is zero (i.e., it is divisible by 10), the number is valid. In our case, 29 + 31 = 60, so the credit card number is valid.

Example Execution #1

Input a credit card number to check its validity.
NUMBER> 6 0   1 1 624 9 8671 7892 7 8 9 9
Sum 1: 46
Sum 2: 56
Overall Sum: 102
The credit card number is invalid.
OUTPUT Invalid
The correct check digit is 7.
OUTPUT 7

 

Example Execution #2

Input a credit card number to check its validity.
NUMBER> 5456 6874 5689 3405
Sum 1: 46
Sum 2: 24
Overall Sum: 70
The credit card number is valid.
OUTPUT Valid

 

Example Execution #3

Input a credit card number to check its validity.
NUMBER> 4543   656 7 3323 6761
Sum 1: 34
Sum 2: 38
Overall Sum: 72
The credit card number is invalid.
OUTPUT Invalid
The correct check digit is 9.
OUTPUT 9

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education