#initial variables and misc import random animals = ["duck", "goat", "bear", "lion", "frog", "deer", "swan", "wolf", "crab"] guessesLeft = 6 isValid = False #introductory paragraph print(" ----ANIMAL WORDLE----") print("Wordle is a word game that was created and developed by Welsh software engineer Josh Wardle.\nIn the original version of Wordle, players have six attempts to guess a five-letter word,\nwith feedback given for each guess in the form of coloured tiles indicating when letters\nmatch or occupy the correct position.") print("") print("In Animal Wordle, players have six attempts to guess a four-letter animal, \nwith feedback given for each guess indicating when letters match or occupy the correct position. \nIf the character is in the correct position, it is indicated with a hash (#). If a character is correct, \nbut in the wrong position, it is indicated with a hyphen (-). If a character is incorrect, \nit is represented with a full stop (.).") print("") print("Unlike in other forms of Wordle, the number of hyphens in this paticular program is not directly proportional \nto the instances of a guessed letter, they simply show that there is at least one of that letter somewhere.\nThis should go without saying, but inputting numbers, symbols or more than a singular letter will always display a '.'.") print("") userName = input("What is your name? ") print("Welcome " + userName + ".") while isValid == False: userDecision = str(input("Would you like to play Animal Wordle? [y/n]:")) if userDecision.lower() == "y" or userDecision.lower() == "yes" or userDecision.lower() == "affirmative" or userDecision.lower() == "absolutely": isValid = True #chooses animal & turns its constituent letters into variables answer = random.choice(animals) answerLetter1 = answer[0] answerLetter2 = answer[1] answerLetter3 = answer[2] answerLetter4 = answer[3] print("") print("You are now playing Animal Wordle") while guessesLeft > 0: #player guess print("") print("You have " + str(guessesLeft) + " guesses left") print("Enter your guess below:") guessLetter1 = str(input(" Letter 1:")) guessLetter2 = str(input(" Letter 2:")) guessLetter3 = str(input(" Letter 3:")) guessLetter4 = str(input(" Letter 4:")) #feedback calculations if guessLetter1.lower() == answerLetter1: feedbackDisplay1 = "#" elif guessLetter1.lower() == answerLetter2 or guessLetter1 == answerLetter3 or guessLetter1 == answerLetter4: feedbackDisplay1 = "-" else: feedbackDisplay1 = "." if guessLetter2.lower() == answerLetter2: feedbackDisplay2 = "#" elif guessLetter2.lower() == answerLetter1 or guessLetter2 == answerLetter3 or guessLetter2 == answerLetter4: feedbackDisplay2 = "-" else: feedbackDisplay2 = "." if guessLetter3.lower() == answerLetter3: feedbackDisplay3 = "#" elif guessLetter3.lower() == answerLetter2 or guessLetter3 == answerLetter1 or guessLetter3 == answerLetter4: feedbackDisplay3 = "-" else: feedbackDisplay3 = "." if guessLetter4.lower() == answerLetter4: feedbackDisplay4 = "#" elif guessLetter4.lower() == answerLetter2 or guessLetter4 == answerLetter3 or guessLetter4 == answerLetter1: feedbackDisplay4 = "-" else: feedbackDisplay4 = "." #feedback display print(feedbackDisplay1 + feedbackDisplay2 + feedbackDisplay3 + feedbackDisplay4) if guessLetter1.lower() == answerLetter1 and guessLetter2.lower() == answerLetter2 and guessLetter3.lower() == answerLetter3 and guessLetter4.lower() == answerLetter4: print("Congratulations, you guessed the right word!") break guessesLeft = guessesLeft - 1 if guessesLeft == 0: print("You have run out of guesses, better luck next time.") #player decides not to play elif userDecision.lower() == "n" or userDecision.lower() == "no" or userDecision.lower() == "negative": isValid = True print() print("Catch you later then.") #player's inputs are invalid else: print("That is a non-valid input, try again.") print("")