-
Notifications
You must be signed in to change notification settings - Fork 342
corrigindo exercício 22 da lista de python #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -396,7 +396,7 @@ Escreva um programa que converta a temperatura de Celsius para Fahrenheit. O pro | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ### Exercício 22: Verificador de Palíndromo | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Crie um programa que verifica se uma palavra ou frase é um palíndromo (lê-se igualmente de trás para frente, desconsiderando espaços e pontuações). Utilize `try-except` para garantir que a entrada seja uma string. Dica: Utilize a função `isinstance()` para verificar o tipo da entrada. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Crie um programa que verifica se uma palavra ou frase é um palíndromo (lê-se igualmente de trás para frente, desconsiderando espaços e pontuações). Utilize `try-except` para garantir que a entrada seja uma string. Dica: Utilize a função `isdigit()` para verificar o tipo da entrada. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ### Exercício 23: Calculadora Simples | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -426,15 +426,16 @@ except ValueError: | |||||||||||||||||||||||||||||||||||||||||||||||
| ### Exercício 22: Verificador de Palíndromo | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ```python | ||||||||||||||||||||||||||||||||||||||||||||||||
| entrada = input("Digite uma palavra ou frase: ") | ||||||||||||||||||||||||||||||||||||||||||||||||
| if isinstance(entrada, str): | ||||||||||||||||||||||||||||||||||||||||||||||||
| formatado = entrada.replace(" ", "").lower() | ||||||||||||||||||||||||||||||||||||||||||||||||
| if formatado == formatado[::-1]: | ||||||||||||||||||||||||||||||||||||||||||||||||
| print("É um palíndromo.") | ||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
| print("Não é um palíndromo.") | ||||||||||||||||||||||||||||||||||||||||||||||||
| palavra = input('Forneça uma palavra ou frase: ') | ||||||||||||||||||||||||||||||||||||||||||||||||
| if palavra.isdigit(): | ||||||||||||||||||||||||||||||||||||||||||||||||
| print("Digite uma palavra ou frase, por favor") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+429
to
+431
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ótima sugestão, @gecofever! O código está funcional, mas gostaria de propor alguns ajustes para torná-lo mais robusto e alinhado a boas práticas.
Segue a sugestão com base nesses pontos:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| print("Entrada inválida. Por favor, digite uma palavra ou frase.") | ||||||||||||||||||||||||||||||||||||||||||||||||
| palavra_tratada = palavra.replace(" ", "").lower() | ||||||||||||||||||||||||||||||||||||||||||||||||
| palavra_invertida = palavra_tratada[::-1] | ||||||||||||||||||||||||||||||||||||||||||||||||
| if palavra_tratada == palavra_invertida: | ||||||||||||||||||||||||||||||||||||||||||||||||
| print(f'{palavra}, é palidromo') | ||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||
| print(f'{palavra}, não é palidromo') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+433
to
+438
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| ### Exercício 23: Calculadora Simples | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.