Jennie K.

asked • 03/19/23

Write a function durdle_game(target) which takes in as an argument a single string that will be the target to guess, and lets the user attempt to guess the target word

Write a function durdle_game(target) which takes in as an argument a single string that will be the target to guess, and lets the user attempt to guess the target word. Before their first guess, the function should print out how many letters are in the target word.


Each time the user makes a guess, the function will print out the result of the previous function to tell the user how close they are. If the user guesses correctly, then the game is over. Have the function return the number of guesses that it took the user to get the correct answer.


If the user guesses something that isn’t the correct length, or something that doesn’t consist only of lowercase letters, then the function should print out “Invalid guess.”. Don’t count invalid guesses towards the number of guesses the user took to get the correct answer.

Examples (text in bold is returned, text in red is user input.):


>>> durdle_game('trick')

Welcome to Durdle! The target word has 5 letters.

Enter a guess:touch

              GBBGB

Enter a guess:truck

              GGBGG

Enter a guess:trick

              GGGGG

Congratulations, you got it in 3 guesses!

3



1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.