0
list1 = list(input("Number: ").strip())
  
even_count, odd_count, count = 0, 0, 0
  
# if the length is even
if len(list1)%2 == 0:
    # iterating each number in list 
    for num in list1: 
        # checking if index is even 
        if int(count) % 2 == 0: 
            even_count += 2*int(num)
      
        else: 
            odd_count += int(num)
        count += 1
else:
    # iterating each number in list 
    for num in list1: 
        # checking condition 
        if int(count) % 2 == 0: 
            even_count += int(num)
      
        else: 
            odd_count += 2*int(num)
        count += 1
        
print(even_count + odd_count)
1
  • the output of even_count + odd_count is not correct for certain card numbers, not sure why. – Anurag Reggie Jul 24 '20 at 15:50
1

Looks like one step in Luhn's is missing:

  • Multiply every other digit by 2, starting with the number’s second-to-last digit, and then add those products’ digits together.
1
  • Thanks, I’ll get back if I manage to do it – Anurag Reggie Jul 24 '20 at 16:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .