1

Function is not being called inside another function:

ch = False
while not ch:
     print("""
        1. Make a User
        2. Login in and Play
        3. Quit

   """)
     a = input("What would you like to do: ")
     if a == '1':
        un_maker()
     elif a == '2':
        player1Login()
     elif a == '3':
        input('\nEnter to exit...\n')
        quit()

Where when a is 2, it should move on to player1Login(), it does but it does not go to the next function inside the player1Login().

The code for player1Login() and the function it's supposed to run:

 def player1Login():
     """ Login for player 1 """
     user1 = input("Please enter your usernames[Caps sensitive]:  ") # Asking the 
     user to input there username
     pass1 = input("Please also enter your password[Caps sensitive]: ") # Asking the user to input there password
     verfi1(user1, pass1)

  def verfi1(user1, pass1):
     """ Verfications of the user """
     with open("data.csv", "r") as f:
        reader = csv.reader(f) # makes 'reader' the csv reader of file 'f'
        for row in reader: # Looking at rows/records inside the file
            if user1 in row: # Looks for username inside the row
                if pass1 in row[1]:
                     print("Player 1 Confirmed") 
                     player2Login()
                elif pass1 != row[1] or reader == '':
                     print("""You have entered the wrong Username/Password for Player 1
                              This could be due to:
                              1. Inputed the wrong username/password
                              2. Inputed the wrong case in username/password
                              3. Inputed username/password that does not exit
                           """)
                     break
            else:
                 #print("Reader")
                 next(reader)

Basically, the code should output when a is 2, player1Login() then move onto verfi1() function however it does not, it just goes back to the menu.

Answer Found:

def menu():
    ch = False
    optin = 0
    while not ch :
           print("""
                1. Make a User
                2. Login in and Play
                3. Quit
                """)
           optin = input("What would you like to do: ")
           if optin == '1':
               un_maker()
           elif optin == '2':
               player1Login()
           elif optin == '3':
               input('\nEnter to exit...\n')
               quit()

def player1Login():
""" Login for player 1 """
    user1 = input("Please enter your usernames[Caps sensitive]:  ") 
    pass1 = input("Please also enter your password[Caps sensitive]: ")
    boop(user1, pass1)

def boop(user1, pass1):
    with open('data.csv', 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            if pass1 in row[1] and user1 in row[0]:
                 print("Username and Password found, Player 1 Confirmed")
                 player2Login(user1)
            elif pass1 not in row[1] and user1 not in row[0] and row[0] == '' :
                 print("Player Not found / Password incorrect")
                 menu()
2
  • You have nothing inside the for row in reader: loop. Is the next line supposed to be indented inside it? Commented Oct 24, 2018 at 21:21
  • Yes its supposed to be indented, i cant get used to the way to do code blocks Commented Oct 24, 2018 at 22:33

1 Answer 1

2

You skip lines with next and therefore jump over each other user in you data.csv file. This can lead to that if user1 in row is never true even though user1 is in your file but happens to be on a skipped line.

Your code:

for row in reader: # Looking at rows/records inside the file
    if user1 in row: # Looks for username inside the row
        if pass1 in row[1]:
            print("Player 1 Confirmed") 
            player2Login()
        elif pass1 != row[1] or reader == '':
            print("""You have entered the wrong Username/Password for Player 1
            This could be due to:
            1. Inputed the wrong username/password
            2. Inputed the wrong case in username/password
            3. Inputed username/password that does not exit
            """)
            break
    else:
        next(reader) # this skips the next

Remove the elseclause because for row in reader already goes over all lines.

Sign up to request clarification or add additional context in comments.

4 Comments

Well i tried this before but the code just looks at the lines without doing anything, which is why i added next(reader) to get it to move on to the next line and read whats there. Thanks for the help though
Make user the user name you type is in your csv file.
Yes,the same username is typed, which the program skips when trying to find the same username and outputs the elif statement.
I've gotten it to work so thanks for the help. Also I'll update to show the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.