The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

query related to Luhn_Algorithm_solution:

query related to Luhn_Algorithm_solution:

0
Votes
0
Answer

I got the solution for validating credit card number I want to understand the logic behind second if statement where we put if condition of number*2 > 9 will be multiplied by two and subtracted by 9:
num_list = [int(char) for char in number]
num_len = len(num_list)
num_list_rev = num_list[::-1]
double = 0
single = 0

for i in range(0,num_len):
        if i%2 != 0:

               if 2*num_list_rev[i]>9:
                        double = double + 2*num_list_rev[i] – 9
               else:
                        double = double + 2 * num_list_rev[i]
        else:
               single = single + num_list_rev[i]
if (double+single)%10 == 0:
          print(f'{number} is a valid credit card number.’)
else:
          print(f'{number} is not a valid credit card number.’)

No answers so far.
×
LAST CHANCE
Ready to Learn Data Science?
50% OFF