🛠️ Scheduled Maintenance | We’ll be undergoing scheduled maintenance and upgrades between 00:00 PST Jan 26th until 00:00 PST Jan 28th. There may be brief interruption of services in that period. We apologize for the inconvenience.

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.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

query related to Luhn_Algorithm_solution:

query related to Luhn_Algorithm_solution:


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
                        double = double + 2 * num_list_rev[i]
               single = single + num_list_rev[i]
if (double+single)%10 == 0:
          print(f'{number} is a valid credit card number.’)
          print(f'{number} is not a valid credit card number.’)

No answers so far.