Created
March 30, 2020 06:36
-
-
Save luizomf/52347ad1e7713cbd9b5482fb893d5bf9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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