Created
November 1, 2021 12:44
-
-
Save guilhermecarvalhocarneiro/4ebf184c8125c5b35b8e3d8abe781726 to your computer and use it in GitHub Desktop.
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
""" | |
05. verbing | |
Dada uma string, se seu tamanho for pelo menos 3, | |
adicione 'ing' no seu fim, a menos que a string | |
já termine com 'ing', nesse caso adicione 'ly'. | |
Se o tamanho da string for menor que 3, não altere nada. | |
Retorne o resultado da string. | |
""" | |
def verbing(verbo): | |
# +++ SUA SOLUÇÃO +++ | |
if len(verbo) <= 3: | |
return verbo | |
verbo += 'ly' if(verbo[-3:] == 'ing') else 'ing' | |
return verbo | |
# --- Daqui para baixo são apenas códigos auxiliáries de teste. --- | |
def test(f, in_, expected): | |
""" | |
Executa a função f com o parâmetro in_ e compara o resultado com expected. | |
:return: Exibe uma mensagem indicando se a função f está correta ou não. | |
""" | |
out = f(in_) | |
if out == expected: | |
sign = '✅' | |
info = '' | |
else: | |
sign = '❌' | |
info = f'e o correto é {expected!r}' | |
print(f'{sign} {f.__name__}({in_!r}) retornou {out!r} {info}') | |
if __name__ == '__main__': | |
# Testes que verificam o resultado do seu código em alguns cenários. | |
test(verbing, 'hail', 'hailing') | |
test(verbing, 'swiming', 'swimingly') | |
test(verbing, 'do', 'do') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment