Jan-18-2021, 02:51 PM
Hi all,
I have been asked to design a basic dice roll game over the course of 20 hours, and all was swell until I came across a logic error. The code does function (2 players are able to log in), but the variables User_1 and User_2 don't become true. This means that even if I have created a game, users wouldn't be able to access it.
Cordially,
Hamza.
I have been asked to design a basic dice roll game over the course of 20 hours, and all was swell until I came across a logic error. The code does function (2 players are able to log in), but the variables User_1 and User_2 don't become true. This means that even if I have created a game, users wouldn't be able to access it.
### ------------------------------------------------------------------------------------------------------------------------------ ### Users = open("Usernames.txt","r+") # Users opens a text file, a+ so it can append and read Passwords = open("Passwords.txt","r+") # Passwords opens a text file, a+ so it can append and read User_array = Users.read().splitlines() # Splits file into array Password_array = Passwords.read().splitlines() # Splits file into array User_1 = False # Decalring global variables User_2 = False # Decalring global variables ### ------------------------------------------------------------------------------------------------------------------------------ ### def SignUp(): # Creating function for Sign up system SignUp = True # Declares SignUp true (for WHILE loop) while SignUp == True: # Sets while loop user = input('Create Username: ') # Prompts user to create username password = input('Create Password: ') # Prompts user to create password if user in User_array: print("That user already exsist") # If user already exists output an error message else: # Otherwise Users.write(user) # Writes new Username into file Users.write("\n") # Goes down a line Passwords.write(password) # Writes new Password into file Passwords.write("\n") # Goes down a line Users.close() # Saves Usernames Passwords.close() # Saves Passwords print("WELCOME, ",user,", PLEASE RESTART BEFORE SIGNING IN") # Outputs welcome message SignUp = False # Terminates while loop ### ------------------------------------------------------------------------------------------------------------------------------ ### def LogIn(): # Creating function for log in system userguess = input("Player 1, please input your username >>> ") #assigning a user input to the userguess variable passwordguess = input("Player 1, please input your password >>> ") #assigning a user input to the passwordguess variable while (userguess not in User_array) or (passwordguess not in Password_array): print("INCORRECT DETAILS >>> ") #if the usernames and passwords don't match up, an error message is given userguess = input("Player 1, please input your username >>> ") # Asks for guesses again passwordguess = input("Player 1, please input your password >>> ") # Asks for guesses again else: # Otherwise player_1 = userguess print ("Welcome player 1, player 2 please sign in") # Output a welcome message User_1 = True userguess = input("Player 2, please input your username >>> ") #assigning a user input to the userguess variable passwordguess = input("Player 2, please input your password >>> ") #assigning a user input to the passwordguess variable while (userguess not in User_array) or (passwordguess not in Password_array) or (userguess == player_1): print("INCORRECT DETAILS >>> ") #if the usernames and passwords don't match up, an error message is given userguess = input("Player 2, please input your username >>> ") # Asks for guesses again passwordguess = input("Player 2, please input your password >>> ") # Asks for guesses again else: player_2 = userguess print ("Welcome player 2") # Output a welcome message User_2 = True ### ------------------------------------------------------------------------------------------------------------------------------ ### ### ------------------------------------------------------------------------------------------------------------------------------ ### ### ------------------------------------------------------------------------------------------------------------------------------ ### def rules(): print("""THE RULES ARE: >>> Points rolled on each player’s dice are added to their score. >>> If the total is an even number, an additional 10 points are added to their score. >>> If the total is an odd number, 5 points are subtracted from their score. >>> If they roll a double, they get to roll one extra die and get the number of points rolled added to their score. >>> The score of a player cannot go below 0 at any point. >>> The person with the highest score at the end of the 5 rounds wins. >>> If both players have the same score at the end of the 5 rounds, it will all come down to first blood. >>> Most importantly, have fun! """) ### ------------------------------------------------------------------------------------------------------------------------------ ### ### ------------------------------------------------------------------------------------------------------------------------------ ### ### ------------------------------------------------------------------------------------------------------------------------------ ### def menu(): print("""WELCOME TO DOUBLE OR NOTHING... PLEASE SELECT ONE OF THE FOLLOWING OPTIONS >>> ___________ /\ . . \ / \ . . \ / \__________\ / . / . . / \ / . / \ / . . / \/__________/ ___________ /\ . . \ / \ . . \ / \__________\ / . / . . / \ / . / \ / . . / \/__________/ 1 >>> Register 2 >>> Log in 3 >>> Rules 4 >>> Play 5 >>> Quit """) def choice(): UserChoice = input("CHOOSE OPTION 1, 2, 3, 4, OR 5 >>> ") if UserChoice == "1": SignUp() choice() elif UserChoice == "2": LogIn() choice() elif UserChoice == "3": rules() choice() elif UserChoice == "4": if User_1 == True and User_2 == True: print("game coming soon") else: print("DOUBLE OR NOTHING REQUIRES TWO PLAYERS, PLEASE LOGIN FIRST >>> ") choice() elif UserChoice == "5": quit() elif UserChoice != 1 or 2 or 3 or 4 or 5: print (">>> NOT A VALID OPTION... TRY AGAIN") choice() menu() choice()I would really appreciate any help I receive!
Cordially,
Hamza.