Skip to content

Instantly share code, notes, and snippets.

@gsalibi
Last active March 2, 2022 17:12
Show Gist options
  • Select an option

  • Save gsalibi/4405e7b1eabe2d6589498acf4955b1f9 to your computer and use it in GitHub Desktop.

Select an option

Save gsalibi/4405e7b1eabe2d6589498acf4955b1f9 to your computer and use it in GitHub Desktop.
This validates the IBGE municipal code and returns the 7th digit
def last_digit_ibge(cod6: str):
a = int(cod6[0])
b = (int(cod6[1]) * 2) % 10 + (int(cod6[1]) * 2) // 10
c = int(cod6[2])
d = (int(cod6[3]) * 2) % 10 + (int(cod6[3]) * 2) // 10
e = int(cod6[4])
f = (int(cod6[5]) * 2) % 10 + (int(cod6[5]) * 2) // 10
digit = (10 - (a + b + c + d + e + f) % 10) % 10
return str(digit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment