This is a school project that I'm trying to do, we have to create a program that asks the user if they have already had an account or not. If not they would have to enter a username, the program will have to check whether the username is already used or not.
import csv
with open('accountdatabase.csv')as csvfile:
datareader = csv.reader(csvfile, delimiter=',')
for row in datareader:
print("###################################")
accountq = input("Do You Have An Account? Y/N: ")
create = "pending"
while create != "completed":
if accountq == "N":
print("Please Create An Account:")
print("")
username = input("Please Enter Your Username: ")
password = input("Please Enter A Password: ")
if row[0] == username:
print("Sorry Username Is Already Taken")
else:
print("Username Accepted")
create = "completed"
break
However, when writing the code, I came an across a logic error where whenever I add a new username it only checks the last username on the row, meaning the previous one is not being checked, this leads to the user being able to create a new account with the same usernames.
I still struggle calling in specific data from a specific Period and row no.
This is how I structure my data in the .csv file: