+ 2

I have a problem with the credit validator in code coach

I keep failing the test cases in the credit validator problem Here is my attempt card_number = list(input().strip()) # Remove the last digit from the card number check_digit = card_number.pop() # Reverse the order of the remaining numbers card_number.reverse() processed_digits = [] for index, digit in enumerate(card_number): if index % 2 == 0: doubled_digit = int(digit) * 2 # Subtract 9 from any results that are greater than 9 if doubled_digit > 9: doubled_digit = doubled_digit - 9 processed_digits.append(doubled_digit) else: processed_digits.append(int(digit)) total = int(check_digit) + sum(processed_digits) # Verify that the sum of the digits is divisible by 10 if total % 10 == 0: print("valid") else: print("not valid")

10th Jul 2021, 4:09 PM
MATOVU CALEB
MATOVU CALEB - avatar
3 Answers
+ 4
here is the task description: https://code.sololearn.com/c57Q51G5pJ3T/?ref=app MATOVU CALEB BTW: why do you remove the last digit by using pop() and then later add it to the sum ?
10th Jul 2021, 7:21 PM
Lothar
Lothar - avatar
+ 1
MATOVU CALEB Please post the question here.
10th Jul 2021, 6:43 PM
Calvin Thomas
Calvin Thomas - avatar
0
num = list(input()[::-1]) for i in range(1, len(num)+1, 2): num[i] = str((int(num[i]))*2) num_2 = num for i in range(0, len(num_2)): if int(num_2[i]) > 9: num_2[i] = str(int(num_2[i])-9) print('valid' if len(num_2) == 16 and sum([int(i) for i in num_2 ]) % 2 == 0 else 'not valid')
24th Nov 2021, 1:25 PM
Mas'ud Saleh
Mas'ud Saleh - avatar