Skip to content

Instantly share code, notes, and snippets.

@luizomf
Created March 30, 2020 06:36
Show Gist options
  • Select an option

  • Save luizomf/52347ad1e7713cbd9b5482fb893d5bf9 to your computer and use it in GitHub Desktop.

Select an option

Save luizomf/52347ad1e7713cbd9b5482fb893d5bf9 to your computer and use it in GitHub Desktop.
def contagem_regressiva_recursiva(comeca_em: int = 10, termina_em: int = 0) -> int:
"""
Contagem regressiva iniciando em 'comeca_em' e terminando em 'termina_em'
"""
print(comeca_em)
# Caso-base
if comeca_em <= termina_em:
# Perceba que aqui um valor real é retornado
# e não há mais recursão
return comeca_em
# Caso recursivo
# Esse código será executado sempre, até
# 'comeca_em' se tornar menor ou igual a 'termina_em'
return contagem_regressiva_recursiva(comeca_em - 1)
if __name__ == "__main__":
contagem_regressiva_recursiva()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment