Question

In: Computer Science

The last digit of a credit card number is the check digit, which protects against transcription...

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:

1.) 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.

2.) Double each of the digits that were not included in the preceeding step. Add all digits of the resulting numbers. For example, with the numbers 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.

3.) Add the sums of the two preceding steps. If the last digit of the result is 0, the number is invalid. In our case, 23 + 27 = 50, so the number is valid.

- IN PYTHON, 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.

Solutions

Expert Solution

n=int(input("Enter Credit card Number")) #Reading credit card from user and converting as integer
i=1#variable to identify the odd or even position for calculating sum accordingly
sum1=0#Variable to store the sum Starting from the rightmost digit, form the sum of every other digit.
sum2=0#Variable to store the sum of second step (2.) Double each of the digits that were not included in the preceeding step. Add all digits of the resulting numbers.)
#Loop to find the sum of digits
x=n
while(n>0):
d=n%10#taking the rightmost digit
#print(d)
#if the digit is at odd postion simply add it with previous sum else double the digit and add each digit with sum
if(i%2==1):
sum1=sum1+d
else :
p=2*d
while(p>0):
sum2=sum2+(p%10)
p=int(p/10)
n=int(n/10)#consider the number after removing the rightmost digit which already processd for the next iteration
i=i+1#to identify the odd or even position
print(sum1)#printing first sum
print(sum2)#printing second sum
sum3=sum1+sum2
print(sum3)#printing third sum
# Add the sums of the two preceding steps. If the last digit of the result is 0,
#the number is invalid.
#Taking last digit and checking whether it is zero
if(sum3%10==0):
print("The number is invalid")
print("The number can be valid if check digit is")
print((x%10)+1)#just incrementing the last digit of the number by one
else:
print ("Number is valid")
  

In question it is mentioned that

3.) Add the sums of the two preceding steps. If the last digit of the result is 0, the number is invalid. In our case, 23 + 27 = 50, so the number is valid

The last digit of 50 is 0 then in program it is considered as invalid

Let me know if any thing wrong

using python 3.6.5


Related Solutions

Credit Card Number Check. The last digit of a credit card number is the check digit,...
Credit Card Number Check. The last digit of a credit card number is the check digit, which protects against transcription errors such as error in a single digit or switching two digits. The following method is used to verify actual credit card number 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 43589795, then...
Credit Card Number Check. The last digit of a credit card number is the check digit,...
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...
Suppose that a check digit is assigned to a four-digit number by appending the remainder after...
Suppose that a check digit is assigned to a four-digit number by appending the remainder after division by 7. If the number 36806 has a single-digit error in the first position, determine the possibilities for the correct number.
Problem Description:A very simple algorithm (Luhn Algorithm) to check whether a credit card number is valid...
Problem Description:A very simple algorithm (Luhn Algorithm) to check whether a credit card number is valid is shown below:We assume that there are 16 digits in a credit card number.Start from the first digit of the credit card number as in position 1; second digit as in position 2; so on until the last digit as in position 16;If a digit is in even numbered position, take the digit itself as its representative;If a digit is in odd numbered position,...
Identify precautions for accepting the types of payments: cash, check, credit card, and debit card.   
Identify precautions for accepting the types of payments: cash, check, credit card, and debit card.   
Which of the following is not true regarding a credit card expense? Multiple Choice Credit card...
Which of the following is not true regarding a credit card expense? Multiple Choice Credit card expense may be classified as a "discount" deducted from sales to get net sales. Credit card expense is not recorded by the seller. Credit card expense may be classified as an administrative expense. Credit card expense may be classified as a selling expense. Credit card expense is a fee the seller pays for services provided by the card company.
Is 100202345X a valid ISBN number? If not, what would the correct check digit have to...
Is 100202345X a valid ISBN number? If not, what would the correct check digit have to be ? Solve the congruence 121x ≡ 5 mod 350.
The records of Check$mart Bank show that the average credit card balance of its customers is...
The records of Check$mart Bank show that the average credit card balance of its customers is $3,325 with a standard deviation of $1,500. Assume that the distribution of these credit card balances is approximately normal. (a) What is the probability that an account balance is less than $2,500? (b) What is the probability that an account balance is more than $5,000? (c) What is the probability that an account balance is between $3,000 and $4,000? (d) 99% of account balances...
The legal process by which a creditor protects her interest against claims of third parties is...
The legal process by which a creditor protects her interest against claims of third parties is called A. fixing B. perfection C. bonding D. securitization The general purpose of the UCC is to A. protect the merchant B. protect the consumer C. protect parties from unconscionable contracts D. standardize commercial law and facilitate commercial transactions A filed financing statement is valid for A. three years B. five years C. ten years D. one year When a buyer breaches, the seller...
A number is a Universal Product Code (UPC) if its last digit agrees with the following...
A number is a Universal Product Code (UPC) if its last digit agrees with the following computations: • The sum of the odd position digits (not including the last) is M. That is we add the first digit to the third digit to the fifth digit etc. • The sum of the even position digits (not including the last) is N. • c = (3M + N)%10. • If c = 0 then the check digit is 0. • If...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT