#------------------------------------------------------------------------------------------------------------------- # Name : Python Assessment # Purpose : 11DGT # This code by : Aesir #------------------------------------------------------------------------------------------------------------------- # Constants MAX_CHIPS = 21 # Set Variables P1_Score = 0 P2_Score = 0 Chips_Left = 0 Chips_Taken = 0 # Ask for player names, looping if numbers are used while True : print() P1_Name = input("Enter a name for player 1: ") if P1_Name.isalpha() == True : break else : print() print("Bro really didn't use letters 💀") while True : print() P2_Name = input("Enter a name for player 2: ") if P2_Name.isalpha() == True : break else : print() print("Bro really didn't use letters 💀") # Ask for no. of rounds (Between 1-5) while True : print() Rounds_Left = input("Choose a number of rounds to play (Any Number): ") if Rounds_Left.isdigit() == True : text = Rounds_Left break else : print() print("Bro really didn't use numbers 💀") # Start the game print() print("This is a 21 chips game, be the person taking chips on 0 chips left to win.") Rounds_Left = int(text) while Rounds_Left > 0 : # Set constants Chips_Left = MAX_CHIPS while Chips_Left > 0 : # Set rounds Rounds_Left = (Rounds_Left - 1) # Output game stats print() print("Chips left: {}".format(Chips_Left)) print("Rounds left: {}".format(Rounds_Left)) Chips_Taken = int(Chips_Taken) # Player 1 takes chips while True : print() Chips_Taken = input("{}, choose a number of chips to take (Between 1-3): ".format(P1_Name)) if Chips_Taken == 1 and Chips_Taken != 2 and Chips_Taken != 3 : break if Chips_Taken != 1 and Chips_Taken == 2 and Chips_Taken != 3 : break if Chips_Taken != 1 and Chips_Taken != 2 and Chips_Taken == 3 : break if Chips_Taken != 3 and Chips_Taken != 2 and Chips_Taken != 1 : print("Try again. The number needs to be between 1-3.") Chips_Left = (Chips_Left - Chips_Taken) Chips_Taken = int(Chips_Taken) if Chips_Left < 1 : P1_Score = (P1_Score + 1) break # Output chips left and reset taken variable print() print("Chips left: {}".format(Chips_Left)) Chips_Taken = 0 # Player 2 takes chips while True : print() Chips_Taken = input("{}, choose a number of chips to take (Between 1-3): ".format(P2_Name)) if Chips_Taken > 3 or Chips_Taken < 1 : print("Try again. The number needs to be between 1-3.") if Chips_Taken > 0 and Chips_Taken < 4 : break Chips_Left = (Chips_Left - Chips_Taken) if Chips_Left < 1 : P2_Score = (P2_Score + 1) break # Output final scores and declare winner print() print("{}'s final score:".format(P1_Name)) print(P1_Score) print() print("{}'s final score:".format(P2_Name)) print(P2_Score) print() if P1_Score > P2_Score : print("Which means that {} has won!".format(P1_Name)) if P2_Score > P1_Score : print("Which means that {} has won!".format(P2_Name)) if P1_Score == P2_Score or P2_Score == P1_Score : print("Which means we have a draw!") # End the game while True : break