Question
USING PYTHON Please write program P4.35. Credit Card Number Check. The last digit of a credit card number is the check digit, which protects against
USING PYTHON
Please write program P4.35. Credit Card Number Check. The last digit of a credit card number is the check digit, which protects against transcription errors such as an error in a single digit or switching two digits. The following method is used to verify actual credit card numbers but, for simplicity, we will describe it for numbers with 8 digits instead of 16: Starting from the rightmost digit, form the sum of every other digit. For example, if the credit card number is 4358 9795, then you form the sum 5 + 7 + 8 + 3 = 23. Double each of the digits that were not included in the preceding step. Add all digits of the resulting numbers. For example, with the number given above, doubling the digits, starting with the next-to-last one, yields 18 18 10 8. Adding all digits in these values yields 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27. Add the sums of the two preceding steps. If the last digit of the result is 0, the number is valid. In our case, 23 + 27 = 50, so the number is valid. Write a program that implements this algorithm. The user should supply an 8-digit number, and you should print out whether the number is valid or not. If it is not valid, you should print the value of the check digit that would make it valid. The program requires
2 FOR loops, 1 IF THEN ELSE statement. Some Hints from Instructor Manua lThere are 4 major sections of the program:1. Compute the sum of the digits at odd indices.?Use a FOR loop here?Before trying to use a loop, work with a sample 8-digit number by hand and on paper?From the hand-calculation steps, figure out the two things you need for a loop; i.e.,oWhat steps need to be repeated?oHow many times these steps need to be repeated?? Once you have both, then try to create a FOR loop2.
Compute the sum of the digits of the doubles of the digits at even indices.?Use a FOR loop here, too?Use instructions from preceding FOR loop3. Compute the total of the sums from the odd digits and the even digits.4. Display whether or not the credit card number was valid.?Use IF THEN - ELSE
Compute what the check digit should be (this can be the ELSE part of the above IF statement)
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