checkdigit.parity.missing

checkdigit.parity.missing(data: str, even: bool = True) str[source]

Calculates a missing digit represented by a question mark.

Parameters:
  • data – A string containing a question mark representing a missing digit.

  • even – Whether to use even or odd parity (defaults to even)

Returns:

The missing binary digit

Return type:

str

Examples

>>> from checkdigit import parity
>>> # Even parity
>>> parity.missing("01?00")
'1'
>>> parity.missing("01?100")
'0'
>>> # Odd parity
>>> parity.missing("01101?", False)
'0'
>>> parity.missing("010010?011", False)
'1'