-1

I'm starting programming on Python and I'm having a very hard time understanding some concepts. If the user selects option 3, the program has to show the results of two lists. The problem is that after the login is successful, the lists are not displayed. If someone could help me I would be very grateful.

list_login = []
list_password = []
list_employees = ['Pedro' , 'Ana', 'Carlos', 'Maria Clara', 'João Antônio']
list_salaries = [3470.00, 2200.00, 3970.34, 7450.23, 5677.33]

def check(login_user):
    if login_user in list_login:
        return True
    else:
        return False


def authentication(index,user_password):
    if list_password[index] == user_password:
        print('User authenticated!')
        return True
    else:
        print('Incorrect Password!')
        return False

    
def login():
    login_user = input('Type your login: ')
    user_password = input('Type your password: ')
    if check(login_user):
        index = list_login.index(login_user)
        authentication(index,user_password)
        
    else:
        print("Login information is incorrect or does not exist.")
        

def new_login():
    name = input('Type your name: ')
        
    if name not in list_employees:
            print('Name is not in the emplyee list, type again!')
            
    if name in list_employee:
            login_user = input('Type the login you wish to register: ')
            
            if login_user not in list_login:
                print('Login is available!')

            if login_user in list_login:
                print('There is already a user registered with this login')
                    
            else:
                password_user = input('Type the password that will be registered: ')

                list_login.append(login_user)
                list_password.append(password_user)

                print('User registered!')
                print('Employee name: ', name)
                print('Login saved: ', login_user)
                print('Password saved: ', password_user)


def create_employee():
    name = input('Type the name of the new employee: ')
    salary = float(input('Type the employee's salary: '))
    list_employees.append(name)
    list_salaries.append(salary)

    print('Employee ',name,' registered with the current salary of: ',salary)




while True:
    choice = input(
    '''
    
    MENU
    1- Create Login and Password
    2- Increase salary 10%
    3- Report
    4- Create New Employee
    Choose a option: '''
    )

    if choice == '1':
        new_login()
        
        
    if choice == '2':
        login()
    
            
    **if choice == '3':
        if login():
        
            for i in range(len(list_employees)):
                print((list_employees[i]),' - ',(list_salaries[i]))**

        
    if choice == '4':
        create_employee()
  • 2
    The title says the question is about checking whether the function is true. But the question seems to be about formatting the list. Which question are you really asking? – Barmar Jun 21 '22 at 16:24
  • Sorry for the confusion, It's my first time posting at stackoverflow. I've edited my question, the problem is showing the lists only after the login is successful. Thanks for the fast reply! – Deivid Kutter Jun 21 '22 at 16:34
  • Why do you have the `if login()` test inside `if choice=='3'`? What do you expect that to do? And more generally, can you create a [MCVE]? It's hard to tell what is going wrong with so little info. – MegaIng Jun 21 '22 at 16:38
  • If you want to login during choice 2 and not again in choice 3, save the result of `login()` in a variable. Then check that variable in choice 3. – Barmar Jun 21 '22 at 16:40
  • Why don't all the options require you to login first? – Barmar Jun 21 '22 at 16:41
  • I've translated all functions and variables to english, they all work fine. I need to check login validation only in options 2 and 3. – Deivid Kutter Jun 21 '22 at 16:59
  • 'if login():' tests the truthiness of the return value from login(). Since no return is specified in the function it automatically returns None so the test 'if login()' fails and the lists don't print. To fix that just provide a truthy (True) return on successful login. – Sean C Jun 21 '22 at 17:02

1 Answers1

1

Now that I see your code, it seems that the answer to your question is that you want to add some return statements:

def login():
    login_user = input('Type your login: ')
    user_password = input('Type your password: ')
    if check(login_user):
        index = list_login.index(login_user)
        authentication(index,user_password)
        return True
    else:
        print("Login information is incorrect or does not exist.")
        return False


Cargo23
  • 3,064
  • 16
  • 25
  • 1
    Thanks very much! This worked flawlessly. I thank you and everyone in this thread for the help provided. It's my first time using the site, and I'm very surprised for the speed in wich people came to answer! – Deivid Kutter Jun 21 '22 at 17:20