-
Notifications
You must be signed in to change notification settings - Fork 60
Feature tarea buenas practicas #8
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 |
|---|---|---|
| @@ -1,34 +1,41 @@ | ||
| trueNumber = "1010"; | ||
|
|
||
| class Codebreaker: | ||
|
|
||
| def adivinar(self, numero=None): | ||
| if trueNumber == '': | ||
| return 'Number is not defined' | ||
|
|
||
| if numero is None or len(numero) != 4 or 'e' not in list(numero): | ||
| return "error" | ||
|
|
||
| if numero == trueNumber: | ||
| return True | ||
|
|
||
| resultadoX = '' | ||
| resultado_ = '' | ||
| arrayNumber = [] | ||
|
|
||
| for x in len(numero): | ||
| if(arrayNumber[numero[x]] == True): | ||
| return 'error' | ||
|
|
||
| arrayNumber[numero[x]] = True | ||
|
|
||
| numero = list(numero) | ||
|
|
||
| for index, x in numero: | ||
| if trueNumber[index] == numero[index]: | ||
| resultadoX+='X' | ||
|
|
||
| elif x in trueNumber: | ||
| resultado_='_' | ||
|
|
||
| return resultadoX+resultado_ | ||
| TRUE_NUMBER = "1489" | ||
|
|
||
|
|
||
| class CodeBreaker: | ||
|
|
||
| def adivinar(self, numero=None): | ||
| if TRUE_NUMBER == '': | ||
| return 'Number is not defined' | ||
|
|
||
| if numero is None or len(numero) != 4: | ||
| return "Error: number must have 4 digits" | ||
|
|
||
| if numero == TRUE_NUMBER: | ||
| return True | ||
|
Owner
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. Te recomiendo mantener constancia en el tipo de valor que vas a retornar, ya que en este momento estás combinando entre strings y booleans |
||
|
|
||
| caracter = '' | ||
| array_number = [1] | ||
|
Owner
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. Puedes agregar un comentario a esta variable explicando que hace? |
||
|
|
||
| # Evaluar si un número se repite se repite dentro de la secuencia | ||
| for x in range((len(numero))): | ||
|
|
||
| if numero[x] in array_number: | ||
| return f"Error: you have already entered the number {numero[x]} in position {array_number.index(numero[x])}" | ||
|
|
||
| array_number.append(numero[x]) | ||
|
|
||
| numero = list(numero) | ||
|
|
||
| for num in range(len(numero)): | ||
| # Realiza la búsqueda y compara uno a uno la posición del índice del 'TRUE_NUMBER' | ||
| # con el del número ingresado. | ||
|
|
||
| if TRUE_NUMBER[num] == numero[num]: | ||
| caracter += 'X' | ||
|
|
||
| elif numero[num] in TRUE_NUMBER: | ||
| caracter += '_' | ||
| else: | ||
| caracter += ' ' | ||
|
|
||
| return caracter | ||
|
Owner
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. Podrias modificar la logica para que agrupe primero las (X), luego los (_) bajos y por ultimo los espacios? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,20 @@ | ||
| from codebreaker import Codebreaker | ||
| from codebreaker import CodeBreaker | ||
|
|
||
| intentos_totales = 10 | ||
| codebreaker = Codebreaker() | ||
| INTENTOS_TOTALES = 10 | ||
| codebreaker = CodeBreaker() | ||
|
|
||
| intento = 0 | ||
|
|
||
| print('Jugar Codebreaker!') | ||
| print('Play Codebreaker!') | ||
|
|
||
| while intento != intentos_totales: | ||
| number = input('Numero:'); | ||
| resolve = codebreaker.adivinar(number) | ||
| print(resolve) | ||
| if resolve == True: | ||
| print('You win!!') | ||
| break | ||
| while intento != INTENTOS_TOTALES: | ||
|
|
||
| number = input('Numero:').strip() | ||
| resolve = codebreaker.adivinar(number) | ||
| print(resolve) | ||
|
|
||
| if resolve == True: | ||
| print('You win!!') | ||
| break | ||
|
|
||
| intento += 1 |
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.
Combinas nombres de variables, funciones y constantes entre español e ingles, te recomiendo mantener constancia con un solo idioma.
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.
Tambien te recomiendo darle un nombre mas descriptivo a esta función.