#Ave import time import sys number = 1 UsernamePassword = [] ScoreUsernamePassword= [] UsefulList = [] #Lists used to store data for passwords as well as checking them. with open("UsernamePassword.csv") as DataFile: for EachLine in DataFile: EachLine=EachLine.strip() EachColumnItem = EachLine.split(",") UsernamePassword.append(EachColumnItem) with open("ScoresUsernamePassword.csv") as DataFile: for EachLine in DataFile: EachLine=EachLine.strip() EachColumnItem = EachLine.split(",") ScoreUsernamePassword.append(EachColumnItem) def Username(): Firstname = str(input("What is your firstname?")) Age = str(input("How old are you")) username = Firstname[:3]+Age print("Your username is:", username) return username #Function To create a username for new users. def Password(): password = str(input("What would you like your password to be")) return password #Asks new user for password of their choice. def NewLogin(UsernamePassword,UsefulList): username = Username() password = Password() UsefulList.append(username) UsefulList.append(password) UsernamePassword.append(UsefulList) with open("UsernamePassword.csv", "w") as DataFile: for EachList in UsernamePassword: for EachItem in EachList: DataFile.write(EachItem + ",") DataFile.write("\n") #^^^^^^^ New login function creates and saves a new user profile. def Login(UsernamePassword,UsefulList,number): WhewHew = 0 username = str(input("What is your username")) password = str(input("What is your password")) for EachList in UsernamePassword: if username and password in UsernamePassword[WhewHew]: Row = WhewHew print("Username and password correct Welcome to the dice game") if number == 3: MainProgram(UsernamePassword,UsefulList,number) else: NewUser(UsernamePassword,UsefulList,number) else: WhewHew = WhewHew+1 print("Username Incorrect") Login(UsernamePassword,UsefulList,number) #^^^^^ Login function manages the Login for current users checking a external file to authenticate their login. def NewUser(UsernamePassword,UsefulList,number): print("Welcome, login will commence in 2 seconds.....") time.sleep(2) print("Hello Player", number) time.sleep(0.5) NewUser = str(input("Are you a new user?")) NewUser = str.upper(NewUser) if NewUser == "NO": number = number+1 Login(UsernamePassword,UsefulList,number) elif NewUser == "YES": number = number+1 NewLogin(UsernamePassword,UsefulList) print("Please Login to authenticate your account......") Login(UsernamePassword,UsefulList,number) else: print("Please enter yes or no") NewUser(UsernamePassword,UsefulList) #This short section of code is what checks if the user is new or not. def MainProgram(UsernamePassword,UsefulList,number): import random FullTotalForone = 0 FullTotalFortwo = 0 for I in range(1,5): input("\nPress enter to roll your first dice, take it in turns. Player One to roll first then Two etc etc.....") time.sleep(0.5) PlayerOneDiceOne = random.randint(1,6) print("Player One your first number is:", PlayerOneDiceOne) PlayerOneDiceTwo = random.randint(1,6) time.sleep(0.5) print("Player One your second number is:", PlayerOneDiceTwo) PlayerTwoDiceOne = random.randint(1,6) time.sleep(0.5) print("Player Two your first number is:", PlayerTwoDiceOne) PlayerTwoDiceTwo = random.randint(1,6) time.sleep(0.5) print("Player Two your second number is:", PlayerTwoDiceOne) PlayerOneTotal = PlayerOneDiceOne+PlayerOneDiceTwo PlayerTwoTotal = PlayerTwoDiceOne+PlayerTwoDiceTwo FullTotalForone = PlayerOneTotal +FullTotalForone FullTotalFortwo = PlayerTwoTotal +FullTotalFortwo print("\nPlayer One Score:",FullTotalForone,"\nPlayer Two Score:", FullTotalFortwo) NewUser(UsernamePassword,UsefulList,number) def Scores(ScoreUsernamePassword): Score= str(input("Do you want to see all the high scores (Top 5)?")) if Score == "yes": print(ScoreUsernamePassword) else: print("Thanks for playing.") forTotalForone = ForTotalForone() forTotalForone = ForTotalFortwo() UsefulList.append(forTotalForone) UsefulList.append(forTotalForone) ScoreUsernamePassword.append(UsefulList) with open("ScoreUsernamePassword.csv", "w") as DataFile: for EachList in UsernamePassword: for EachItem in EachList: DataFile.write(EachItem + ",") DataFile.write("\n") Scores(ScoreUsernamePassword)