Struggling to read from a file using a for loop.

Discussion in 'Python' started by Spuddy, Oct 8, 2019.

  1. Spuddy


    Oct 8, 2019
    Likes Received:
    Here is some of my code:

    username1 = input ("Please enter your username")

    file = open ("login.txt","r")
    for loop in range(2):
    line = file.readline()
    data = line.split (",")
    if data[1] == username1:
    print("Your username is correct, please enter your password")

    It doesn't do the if statement after i use the correct username which can be found in the file i have attached below.
    Any feedback would be greatly appreciated :)

    Attached Files:

    Spuddy, Oct 8, 2019
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.