verification of the correctness of the pesel number wwwgovpl translate googwebgovczymjestnumerpesel xtrslautoxtrtlen pesel can start with 0 that s why we take str as input but convert it to int for some calculations ispolishnationalid123 traceback most recent call last valueerror expected str as input found class int ispolishnationalidabc traceback most recent call last valueerror expected number as input ispolishnationalid02070803628 correct pesel true ispolishnationalid02150803629 wrong month false ispolishnationalid02075503622 wrong day false ispolishnationalid99012212349 wrong range false ispolishnationalid990122123499999 wrong range false ispolishnationalid02070803621 wrong checksum false check for invalid input type check if input can be converted to int check number range check month correctness check day correctness check the checksum multiply corresponding digits and multipliers in case of a doubledigit result add only the last digit verification of the correctness of the pesel number www gov pl translate goog web gov czym jest numer pesel _x_tr_sl auto _x_tr_tl en pesel can start with 0 that s why we take str as input but convert it to int for some calculations is_polish_national_id 123 traceback most recent call last valueerror expected str as input found class int is_polish_national_id abc traceback most recent call last valueerror expected number as input is_polish_national_id 02070803628 correct pesel true is_polish_national_id 02150803629 wrong month false is_polish_national_id 02075503622 wrong day false is_polish_national_id 99012212349 wrong range false is_polish_national_id 990122123499999 wrong range false is_polish_national_id 02070803621 wrong checksum false check for invalid input type check if input can be converted to int check number range check month correctness year 1900 1999 2000 2099 2100 2199 2200 2299 1800 1899 check day correctness check the checksum cut off the checksum multiply corresponding digits and multipliers in case of a double digit result add only the last digit
def is_polish_national_id(input_str: str) -> bool:
    

    
    if not isinstance(input_str, str):
        msg = f"Expected str as input, found {type(input_str)}"
        raise ValueError(msg)

    
    try:
        input_int = int(input_str)
    except ValueError:
        msg = "Expected number as input"
        raise ValueError(msg)

    
    if not 10100000 <= input_int <= 99923199999:
        return False

    
    month = int(input_str[2:4])

    if (
        month not in range(1, 13)  
        and month not in range(21, 33)  
        and month not in range(41, 53)  
        and month not in range(61, 73)  
        and month not in range(81, 93)  
    ):
        return False

    
    day = int(input_str[4:6])

    if day not in range(1, 32):
        return False

    
    multipliers = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]
    subtotal = 0

    digits_to_check = str(input_str)[:-1]  

    for index, digit in enumerate(digits_to_check):
        
        
        subtotal += (int(digit) * multipliers[index]) % 10

    checksum = 10 - subtotal % 10

    return checksum == input_int % 10


if __name__ == "__main__":
    from doctest import testmod

    testmod()