The Program does not advance

Asked

Viewed 41 times

0

I hope you are well! I have tried to make a system that asks for registration and that after confirmation of it, walks to the login screen. Soon after doing the same, new options will appear. The question is: I CAN’T LEAVE THIS PART! Below is the code:

#coding: utf8
#Criado por: Lorran Rocha dos Santos


#--------------BOAS VINDAS--------------#
print("Bem-Vindo!")
welcome = input("Você já tem uma conta? S/N  ")

#--------------VERIFICAR ESCOLHA--------------#
def cadastro(welcome, username, email, cpf, endereco,celular,password,password1):
    if welcome == "n" or "N":
        while True:
            username  = input("Digite um Nome de Usuario:")
            email = input("Digite seu email:")
            cpf = input("Digite seu CPF:")
            endereco = input("Digite seu endereço completo:")
            celular = input("Digite seu numero de celular:")
            password  = input("Digite uma Senha:")
            password1 = input("Confirme sua Senha:")
            if password == password1:
                file = open(username+".txt", "w")
                file.write(username+":"+password)
                file.close()
                welcome = "s"
                break
            print("As senhas não batem!")

def login():

        if welcome == "s" or "S":
            while True:
                login1 = input("Login:")
                login2 = input("Senha:")
                file = open(login1+".txt", "r")
                data   = file.readline()
                file.close()
                if data == login1+":"+login2:
                    print("Bem-Vindo!")
                    break
                print("Usuário ou Senha incorretos.")

1 answer

2


You have a lot of errors in this code snippet.

First mistake: You’re not calling the job cadastro and login anywhere in your script, you just initialized them.

How to correct:

while True:
    welcome = input("Você já tem uma conta? S/N  ")
    if not (welcome == 's' or welcome == 'S' or welcome == 'n' or welcome == 'N'): #Se não for nenhuma desta opções
        break
    if welcome == 's' or welcome == 'S':
        #Call login function
    else:
        #Call cadastro function

Second mistake: Your job cadastro does not need any parameter. The variables you have as parameters, you will get them within the function.

Third mistake: In function cadastro, even if the password matches, you will always print 'The passwords do not match'. The same happens in the login function

How to correct:

if password == password1:
    #Do what you have to do
else:
    print('As senhas não batem!')

#Tens de fazer o mesmo na função de login

Fourth mistake: You are not reading the file correctly. You are only reading one line. What happens if you have registered two or more accounts?

PS: You have more mistakes possible to be improved, I’ll let you find out for yourself, I’ll be here to help solve

  • But what would I call the function?

  • 1

    only login() As the function login no brackets, just call with two curved brackets with nothing in the middle. When a function has parameters, it has to put: funcao(param1, param2)

  • You saved me! Thank you!

  • Do not worry, if you need more help, let us know! Give upvote if it helped, accept the answer if your questions are clarified!

  • Here just keeps saying that the "break" is out of the loop. I try several types of endentation and nothing...

  • Put your current code

Show 2 more comments

Browser other questions tagged

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