-
Notifications
You must be signed in to change notification settings - Fork 60
Matias Rodeghiero #6
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,43 @@ | ||
| trueNumber = "1010"; | ||
|
|
||
| class Codebreaker: | ||
|
|
||
| def adivinar(self, numero=None): | ||
| if trueNumber == '': | ||
| return 'Number is not defined' | ||
| def __init__(self): | ||
| self.TRUE_NUMBER = '1025' | ||
|
|
||
| if numero is None or len(numero) != 4 or 'e' not in list(numero): | ||
| return "error" | ||
|
|
||
| if numero == trueNumber: | ||
| return True | ||
| def adivinar(self, intento=0, numero=None): | ||
|
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 consistencia entre los nombres de las variables y las funciones en un solo idioma 😄 y quizá ser mas específico, como guess_number. |
||
| self.arrayNumber = [] | ||
|
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. Recuerda que se recomienda en pep8 usar snake_case para nombrar las variables |
||
| self.check_truenumber = 0 | ||
|
|
||
| resultadoX = '' | ||
| resultado_ = '' | ||
| arrayNumber = [] | ||
|
|
||
| for x in len(numero): | ||
| if(arrayNumber[numero[x]] == True): | ||
| return 'error' | ||
| # Verifico que se haya ingresado bien el número a adivinar | ||
| # Si no se cumple cancelo la ejecución y doy aviso | ||
| for i in self.TRUE_NUMBER: | ||
| if self.TRUE_NUMBER.count(i) > 1: | ||
| self.check_truenumber += 1 | ||
|
|
||
| arrayNumber[numero[x]] = True | ||
|
|
||
| numero = list(numero) | ||
| if self.TRUE_NUMBER == '' or len(self.TRUE_NUMBER) != 4 \ | ||
| or not self.TRUE_NUMBER.isnumeric() or self.check_truenumber > 0: | ||
| return 0, False | ||
|
|
||
| for index, x in numero: | ||
| if trueNumber[index] == numero[index]: | ||
| resultadoX+='X' | ||
| # Verifico que se cumpla la consigna de ingresar 4 números | ||
| if numero == '' or len(numero) != 4 or not numero.isnumeric(): | ||
| self.intento = intento # No pierde un intento | ||
| return self.intento, \ | ||
| 'Se debe ingresar un número natural de 4 dígitos' | ||
|
|
||
| elif x in trueNumber: | ||
| resultado_='_' | ||
| # Verifico que se cumpla la consigna de digitos no repetidos | ||
| for i in numero: | ||
| if numero.count(i) > 1: | ||
| self.intento = intento # No pierde un intento | ||
| return self.intento, 'No se deben ingresar números repetidos' | ||
|
|
||
| return resultadoX+resultado_ | ||
| # Proceso respuesta de acuerdo a lo ingresado | ||
| if numero == self.TRUE_NUMBER: | ||
| return intento, True | ||
|
Comment on lines
+32
to
+33
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. Recuerda intentar mantener un mismo idioma a través de tus variables |
||
| else: | ||
| self.intento = intento+1 # Pierde un intento | ||
| for x in range(0, len(numero)): | ||
| if numero[x] == self.TRUE_NUMBER[x]: | ||
| self.arrayNumber.append("_") | ||
| elif numero[x] in self.TRUE_NUMBER: | ||
| self.arrayNumber.append("X") | ||
| else: | ||
| self.arrayNumber.append("#") | ||
|
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? |
||
| return self.intento, ''.join(self.arrayNumber) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,25 @@ | ||
| from codebreaker import Codebreaker | ||
|
|
||
| intentos_totales = 10 | ||
| codebreaker = Codebreaker() | ||
|
|
||
| INTENTOS_TOTALES = 10 | ||
| intento = 0 | ||
| codebreaker = Codebreaker() | ||
|
|
||
| print('Jugar 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: ') | ||
| intento, resolve = codebreaker.adivinar(intento, number) | ||
|
|
||
| if isinstance(resolve, bool) and resolve: | ||
| print('You win!!') | ||
| break | ||
| elif isinstance(resolve, bool) and not resolve: | ||
| print('Los números a adivinar no cumplen las condiciones\ | ||
| \nModificar código') | ||
| break | ||
| else: | ||
| print(resolve) | ||
| print(f'Intentos: {intento} de {INTENTOS_TOTALES}') | ||
|
|
||
| if intento == 10: | ||
| print('No lo has logrado :(') |
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.
Nice