Python Forum
New to coding. An error occurs with no definition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to coding. An error occurs with no definition
#1
I am trying to create a user system for my program and I have encountered an error. Any help?
This is the code:
def main():
    loginorregister = input("What would you like to do?\n1. Login\n2. Register\n")
    if loginorregister == "1":
        nameinput = input("Please enter your username: ")
        passinput = input("Please enter your password: ")
        file2 = open("userdata.csv","r")
        for line in file2:
            details = line.split(",")
            print(details[0])
            print(details[1])
            if details[0] == nameinput:
                if details[1] == passinput:
                    print("Welcome!")#Currently broken, No response, working on a solution.
    elif loginorregister == "2":
        usernamename = input("Please enter your name: ")
        usernamenumber = input("Please enter your age: ")
        usernameyear = input("Please enter your year group: ")
        password = input("Please enter a password: ")
        username = usernamename[0:3] + usernamenumber + usernameyear
        print("Your username is: ", username)
        file1 = open("userdata.csv","a")
        file1.write(username + "," + password + "\n")
        file1.close()
        print("Userdata set correctly.")
    else:
        print("ERROR, RESTARTING PROGRAM.")
        main()
main()

if loginorregister == "1":
        nameinput = input("Please enter your username: ")
        passinput = input("Please enter your password: ")
        file2 = open("userdata.csv","r")
        for line in file2:
            details = line.split(",")
            print(details[0])
            print(details[1])
            if details[0] == nameinput:
                if details[1] == passinput:
                    print("Welcome!")#Currently broken, No response, working on a solution.
This part (Line 30) should read the userdata.csv file and print welcome if their username and password were correct, as well as printing the username and password. However, the program does not print welcome, Just the username and password. I have tried removing "print(details[0])" and "print(details[1])" and It comes up with the same blank space where welcome should be.

Does anyone know a fix to this? Huh

[Image: EFDp]
This is what happens.

def main():
    loginorregister = input("What would you like to do?\n1. Login\n2. Register\n")
    if loginorregister == "1":
        nameinput = input("Please enter your username: ")
        passinput = input("Please enter your password: ")
        file2 = open("userdata.csv","r")
        for line in file2:
            details = line.split(",")
            print(details[0])
            print(details[1])
            if details[0] == nameinput:
                if details[1] == passinput:
                    print("Welcome!")#Currently broken, No response, working on a solution.
    elif loginorregister == "2":
        usernamename = input("Please enter your name: ")
        usernamenumber = input("Please enter your age: ")
        usernameyear = input("Please enter your year group: ")
        password = input("Please enter a password: ")
        username = usernamename[0:3] + usernamenumber + usernameyear
        print("Your username is: ", username)
        file1 = open("userdata.csv","a")
        file1.write(username + "," + password + "\n")
        file1.close()
        print("Userdata set correctly.")
    else:
        print("ERROR, RESTARTING PROGRAM.")
        main()
main()
Output:
What would you like to do? 1. Login 2. Register 1 Please enter your username: Jas1611 Please enter your password: letmein222 Jas1611 letmein222
Reply


Messages In This Thread
New to coding. An error occurs with no definition - by westernwhiskey - Mar-15-2018, 12:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Return a definition samh625 6 2,478 Jul-28-2020, 08:32 AM
Last Post: samh625
  Coding error? Mugwash 4 3,151 Apr-06-2018, 06:57 PM
Last Post: Mugwash
  trouble importing class definition from one .py into another ijosefson 3 3,373 Oct-16-2017, 08:24 AM
Last Post: Larz60+
  Python Coding Error MGallo 3 3,791 Jul-20-2017, 02:35 PM
Last Post: MGallo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020