Click Here to go back to the homepage.

Luhn's Checksum Algorithm Solution:


cases = int(input())
for _ in range(cases):
    line = list(input())[::-1]
    for i in range(1, len(line), 2):
        line[i] = int(line[i]) * 2
        if line[i] > 9:
            line[i] = f"{line[i]}"
            line[i] = int(line[i][0]) + int(line[i][1])
    if sum(list(map(int, line))) % 10 == 0:
        print("PASS")
    else:
        print("FAIL")