Skip to content

Instantly share code, notes, and snippets.

@gsalibi

gsalibi/validate_ibge.py

Last active Jun 30, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.