ERROR :My code hangs without any error

Asked

Viewed 123 times

-2

I’m starting to learn python and wanted to create a kind of login, only that the code ends without having chosen to end.

from time import sleep

print('=='*20) print('=='*8,'LOGIN','=='*8) print('=='*19) print() print('TYPE 1 TO EXIT SYSTEM nDIGITE 2 TO CONTINUE') opc=int(input(' 1 or 2 : '))

while True : login = [] password = []

if opc == 1: print() print('FINALIZANDO') print() sleep(3) break if opc == 2 : print('PROCESSANDO') print() sleep(4) print('DIGITE 1 PARA CADASTRO\nDIGITE 2 PARA LOGIN') opc2 = int(input('1 OU 2 : ')) if opc2 == 1: print() print('=='*5,'PROCESSO DE CADASTRAMENTO','=='*5) print() login_1 = input('LOGIN : ') login=login+[login_1] sleep(2) print('SALVO') senha_2 = input('SENHA : ') senha=senha+[senha_2] sleep(2) print('SALVO') print() opc3=input('DESEJA FAZER O LOGIN DIGITE 1 OU 2 PARA SAIR : ') #ERRO APÓS ESCOLHER if opc3 == 2: print() print('FINALIZANDO') sleep(2) break if opc3 == 1: print() print('==' * 5, 'LOGIN', '==' * 5) print() login_1 = input('LOGIN :') if login_1 in login: print() senha_1 = input('SENHA :') if senha_1 in senha: print() print('PROCESSANDO') sleep(3) print('LOGIN EFETUADO') break else: print('SENHA INCORRETA') print() print('DIGITE NOVAMENTE A SENHA') print() if senha_1 in senha: print() print('PROCESSANDO') sleep(3) print('LOGIN EFETUADO') break else: break else: print('VOCÊ NÃO TEM CADASTRO') break else: break else: break if opc2 == 2: print() print('=='*5,'LOGIN','=='*5) print() login_1 = input('LOGIN :') if login_1 in login: print() senha_1 = input('SENHA :') if senha_1 in senha: print() print('PROCESSANDO') sleep(3) print('LOGIN EFETUADO') break else: print('SENHA INCORRETA') print() print('DIGITE NOVAMENTE A SENHA') print() if senha_1 in senha: print() print('PROCESSANDO') sleep(3) print('LOGIN EFETUADO') break else: print('VOCÊ NÃO TEM CADASTRO') break else: break else: break

  • 2

    The code is too confusing. If you simplify it the problem probably goes away by itself.

  • 3

    Programming, among many other things, will involve you identifying patterns and separating the problem into small parts using logical reasoning. At first it can be confusing, but keep insisting until your code is short, only with the minimum of steps necessary to reach the result. Remove repetitions and use language features to control the flow. Let the machine make the decisions instead of yourself make all possible combinations and write one by one.

2 answers

1


If Voce posted your code here exactly the way you did there, then the error is in the recoil of the first while true that Voce did. It will endlessly run the next two lines that define the login and password variables. Correct your program’s setbacks/identation and be happy.

0

As Bacco said, it is interesting to separate the problems into small portions and solve these small portions one by one.

Your code has some problems related to syntax and logic. So let’s go in parts. Below I’ll leave a code that captures an entry and prints it.

Note that the part that captures an entry is in a function, so you can separate the responsibilities of each piece of code, and make things clearer:

# funcao para coleta de dados
def coleta_entrada():
    entrada = input("digite alguma coisa: \n")
    return entrada


while True:  # loop infinitio para executar sua rotina
    retorno = coleta_entrada()
    print('voce digitou: {} \n'.format(retorno))

I think this is a start to what you want to do...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.