Last active
March 5, 2024 18:50
-
-
Save dudanogueira/7af722477c33bd4bb85843cf0e035b77 to your computer and use it in GitHub Desktop.
Validar CNS Cartão Nacional de Saúde em Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Autoria: | |
# Amaury Gonçalves <[email protected]> | |
# Duda Nogueira <[email protected]> | |
# | |
def validaCNS(numero): | |
numero = str(numero) | |
if numero.isdigit(): | |
if re.match(r'[1-2]\d{10}00[0-1]\d$',numero) or re.match(r'[7-9]\d{14}$',numero): | |
return somaPoderada(numero) % 11 == 0 | |
return False | |
def somaPoderada(numero): | |
i = 0 | |
soma = 0 | |
while i<len(numero): | |
soma = soma+int(numero[i]) * (15 - i) | |
i = i+1 | |
return soma |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment