Mar-15-2018, 12:07 PM
(This post was last modified: Mar-15-2018, 12:23 PM by westernwhiskey.)
I am trying to create a user system for my program and I have encountered an error. Any help?
This is the code:
Does anyone know a fix to this?
![[Image: EFDp]](https://imageupload.co.uk/image/EFDp)
This is what happens.
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?

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