def ISBNcheck(ISBN):

    # Split the ISBN into the Unique ID and the check digit
    unique_id = []
    for i in range(len(ISBN)-1):
        unique_id.append(int(ISBN[i]))
    actual_check_digit = ISBN[-1:]

    # Multiply the second, fourth, sixth, ... elements by three
    times_three=[]
    for x in range(len(unique_id)):
        if x%2 == 0:
            times_three.append(unique_id[x]*3)
        else:
            times_three.append(unique_id[x])

    # Calculate the sum of the numbers
    sum_new_digits = 0
    for x in range(0,len(times_three)):
        sum_new_digits += times_three[x]
        

    # Take the sum mod 10, and subtract from 10
    sum_mod_10 = sum_new_digits % 10
    if sum_mod_10 == 0:
        sum_mod_10 = 10
    check_digit = 10 - sum_mod_10



    # Check that the calculated check digit is equal to the given check digit
    if check_digit == actual_check_digit:
        return "valid."
    else:
        return "invalid."

choice = input("Enter the ISBN number: ")
print("ISBNcheck() returns " + ISBNcheck(choice))
