https en wikipedia orgwikicheckdigitalgorithms returns the last digit of barcode by excluding the last digit first and then computing to reach the actual last digit from the remaining 12 digits getcheckdigit8718452538119 9 getcheckdigit87184523 5 getcheckdigit87193425381086 9 getcheckdigitx for x in range0 100 10 0 7 4 1 8 5 2 9 6 3 extract and check each digit checks for length of barcode and lastdigit returns boolean value of validity of barcode isvalid8718452538119 true isvalid87184525 false isvalid87193425381089 false isvalid0 false isvaliddwefgiweuf traceback most recent call last nameerror name dwefgiweuf is not defined returns the barcode as an integer getbarcode8718452538119 8718452538119 getbarcodedwefgiweuf traceback most recent call last valueerror barcode dwefgiweuf has alphabetic characters enter a barcode returns the last digit of barcode by excluding the last digit first and then computing to reach the actual last digit from the remaining 12 digits get_check_digit 8718452538119 9 get_check_digit 87184523 5 get_check_digit 87193425381086 9 get_check_digit x for x in range 0 100 10 0 7 4 1 8 5 2 9 6 3 exclude the last digit extract and check each digit checks for length of barcode and last digit returns boolean value of validity of barcode is_valid 8718452538119 true is_valid 87184525 false is_valid 87193425381089 false is_valid 0 false is_valid dwefgiweuf traceback most recent call last nameerror name dwefgiweuf is not defined returns the barcode as an integer get_barcode 8718452538119 8718452538119 get_barcode dwefgiweuf traceback most recent call last valueerror barcode dwefgiweuf has alphabetic characters enter a barcode
def get_check_digit(barcode: int) -> int:
    
    barcode //= 10  
    checker = False
    s = 0

    
    while barcode != 0:
        mult = 1 if checker else 3
        s += mult * (barcode % 10)
        barcode //= 10
        checker = not checker

    return (10 - (s % 10)) % 10


def is_valid(barcode: int) -> bool:
    
    return len(str(barcode)) == 13 and get_check_digit(barcode) == barcode % 10


def get_barcode(barcode: str) -> int:
    
    if str(barcode).isalpha():
        msg = f"Barcode '{barcode}' has alphabetic characters."
        raise ValueError(msg)
    elif int(barcode) < 0:
        raise ValueError("The entered barcode has a negative value. Try again.")
    else:
        return int(barcode)


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    
    barcode = get_barcode(input("Barcode: ").strip())

    if is_valid(barcode):
        print(f"'{barcode}' is a valid barcode.")
    else:
        print(f"'{barcode}' is NOT a valid barcode.")