#Set MAX_CHIPS constant to 21 MAX_CHIPS = 21 #Set PlayerOneSscore to 0 playeronescore = 0 #Set PlayerTwoScore to 0 playertwoscore = 0 #Set chipsLeft to 0 chipsleft = 0 #Set chipsTaken to 0 chipstaken = 0 #Get playerOneName through user input def names(): global playerone global playertwo while True: playerone = str(input("Player one enter your name:")) if playerone.isalpha() == True: break else: print("This name is not a valid name, try again") #Get playerTwoName through user input while True: playertwo = str(input("Player two enter your name:")) if playertwo.isalpha() == True: game_main() break else: print("This name is not a valid name, try again") #globals def game_main(): global chipsleft global MAX_CHIPS global chipstaken global rounds global playeronescore global playertwoscore #Get rounds through user input while True: try: rounds = int(input("How many rounds would you like to play? 1-5:")) if 1 <= rounds <= 5: break else: print("Please choose a number from 1 to 5") except: print("If you don't input a number I can't process what to do next, try again") while rounds > 0: #chipsLeft = MAX_CHIPS chipsleft = MAX_CHIPS #While chipsLeft is greater than zero while chipsleft > 0: while True: try: #Get player1 chosen amount of chips to take chipstaken = int(input(f"{playerone} how many chips would you like to take 1-3?")) if chipstaken < 1 or chipstaken > 3: print("You can only take 1 to 3 chips, try again") else: chipsleft -= chipstaken break except: print("If you don't input a number I can't process what to do next, try agian") #If chipsLeft is lesser than one if chipsleft <= 0: print(f"\n {playerone} has won this round\n") #Add 1 to playerOneScore playeronescore += 1 #Break from loop break #Output chipsLeft print("There is now", chipsleft,"chips left") while True: try: #Get player2 chosen amount of chips to take chipstaken = int(input(f"{playertwo} how many chips would you like to take 1-3?")) if chipstaken < 1 or chipstaken >3: print("You can only take 1 to 3 chips, try again") else: chipsleft -= chipstaken break except: print("If you don't input a number I can't process what to do next, try again") #If chipsLeft is lesser than one if chipsleft <= 0: print(f"\n {playertwo} haas won this round\n") #Add 1 to playerTwoScore playertwoscore += 1 #Break from loop break #Update chipsLeft print("There is", chipsleft,"chips left") #Minus 1 from rounds rounds -= 1 #Check who has the higher score and output the winner if rounds == 0: print(f"\n{playerone}'s score was", playeronescore,) print(f"{playertwo}'s score was", playertwoscore,) if __name__ == "__main__": names()