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)
-
the output of even_count + odd_count is not correct for certain card numbers, not sure why.– Anurag ReggieCommented Jul 24, 2020 at 15:50
Add a comment
|
1 Answer
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.