-
Notifications
You must be signed in to change notification settings - Fork 265
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
Desafio3 #1020
Merged
Merged
Desafio3 #1020
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Calculadora de Palíndromos | ||
|
||
## Visão Geral | ||
Este script foi projetado para calcular e recuperar números palíndromos com base em limites e intervalos definidos pelo usuário. | ||
|
||
## Requisitos | ||
|
||
Para executar este módulo, basta ter uma versão do Python 3.10+ e executar a seguinte linha de comando no terminal: | ||
``` | ||
python.exe __main__.py | ||
``` | ||
|
||
## 2. Implementação | ||
|
||
### Uso | ||
1. O script solicita ao usuário que insira o limite de cálculo (até 1000000). | ||
2. O script solicita ao usuário a quantidade de números palíndromos a serem exibidos. | ||
3. Se nenhum valor for fornecido para o limite ou intervalo, valores padrão são definidos. | ||
|
||
### Observação | ||
- O limite e o intervalo são validados para garantir que atendam aos critérios especificados. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from palcalc import PalCalc | ||
|
||
if __name__ == "__main__": | ||
|
||
pn = PalCalc() | ||
for i in pn.get_pal(): | ||
print(i) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Create class for calculating the palindromes | ||
class PalCalc(): | ||
""" | ||
Unique class to store the calculation logic | ||
""" | ||
def get_pal(self): | ||
""" | ||
Calculates the palindromes and returns a list of them based on the limit and range. | ||
""" | ||
|
||
# Get the limit and range | ||
pallimit = self.get_valid_limit() | ||
palrange = self.get_valid_range() | ||
pallist = {i for i in range(1, pallimit + 1) if str(i) == str(i)[::-1]} | ||
return list(pallist)[:palrange] if palrange != 0 else list(pallist) | ||
|
||
def get_valid_limit(self): | ||
""" | ||
Validates and returns the calculation limit. | ||
""" | ||
while True: | ||
pallimit = input("Enter the calculation limit: ") | ||
try: | ||
pallimit = float(pallimit) | ||
if pallimit < 0: | ||
print("Please enter a positive number.") | ||
elif pallimit > 1000000: | ||
print("The limit is too high. Please enter a number less than 1000000.") | ||
else: | ||
break | ||
except ValueError: | ||
pallimit = pallimit.strip() | ||
if pallimit == "": | ||
pallimit = 100.0 | ||
print("No given limit. It has been automatically set to 100.") | ||
break | ||
print("Invalid input. Please enter a valid number.") | ||
if round(pallimit) != pallimit: | ||
print(f"The limit has been rounded to the nearest integer: {round(pallimit)}") | ||
pallimit = int(round(pallimit)) | ||
if pallimit == 0: | ||
print("The limit has been automatically set to 100.") | ||
pallimit = 100 | ||
return pallimit | ||
|
||
def get_valid_range(self): | ||
""" | ||
Validates and returns the number of prime numbers to be displayed. | ||
""" | ||
while True: | ||
palrange = input("Enter the number of prime numbers to be displayed (0 = all): ") | ||
try: | ||
palrange = float(palrange) | ||
if palrange < 0: | ||
print("Please enter a positive number.") | ||
elif palrange > 1000000: | ||
print("The limit is too high. Please enter a number less than 1000000.") | ||
else: | ||
break | ||
except ValueError: | ||
palrange = palrange.strip() | ||
if palrange == "": | ||
palrange = 0 | ||
print("No given limit. All numbers will be printed.") | ||
break | ||
print("Invalid input. Please enter a valid number.") | ||
if round(palrange) != palrange: | ||
print(f"The limit has been rounded to the nearest integer: {round(palrange)}") | ||
palrange = int(round(palrange)) | ||
return palrange |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Este comentário só vai funcionar para quem usar Windows