import random # Author: James Tam # Version: 2022 MIN_NUM = 1 MAX_NUM = 10 MIN_COLOR = 1 MAX_COLOR = 3 MAX_GUESSES = 10 RED = 1 BLUE = 2 GREEN = 3 def processGuessingColor(): stillGuessingColor= True guessedColor = False numericColor = -1 actualColor = "" playColor = "" i = 1 numericColor = random.randrange(MIN_COLOR,MAX_COLOR)+1 while (stillGuessingColor == True): if (numericColor == RED): actualColor = "red" if (numericColor == BLUE): actualColor = "blue" if (numericColor == GREEN): actualColor = "green" playerColor = input("Guess color (red, blue, green): ") if (playerColor == actualColor): print("Guessed actual the color %s" %(actualColor)) stillGuessingColor = False guessedColor = True if ((i > MAX_GUESSES) and (guessedColor == False)): stillGuessingColor = False print("Exceeded maximum tries of %d" %(MAX_GUESSES)) i = i + 1 return(guessedColor) def processGuessingNumber(): stillGuessingNum= True guessedNumber = False actualNum = -1 playNum = -1 i = 1 actualNum = random.randrange(MIN_NUM,MAX_NUM)+1 while (stillGuessingNum == True): print("Guess a # from %d-%d: " %(MIN_NUM,MAX_NUM), end="") playerNum = int(input()) if (actualNum == playerNum): print("Guessed %d!" %(actualNum)) stillGuessingNum = False guessedNumber = True i = i + 1 if ((i > MAX_GUESSES) and (guessedNumber == False)): stillGuessingNum = False guessedNumber = False print("Exceeded maximum tries of %d" %(MAX_GUESSES)) return(guessedNumber) def start(): gameWon = False while (gameWon == False): guessedNumber = processGuessingNumber() guessedColor = processGuessingColor() input("Press enter to continue") if (guessedNumber == True) and (guessedColor == True): gameWon = True print("You won the game!") start()