I need some help creating a word game in Python

Hello, I’ve recently started to learn about Python (for about 2 months), and I need some help to create a word based game, similar to a game called “Wordle”, for this I need to do the following:

Have a secret word stored in the program.

Prompt the user for a guess.

Continue looping as long as that guess is not correct.

Calculate the number of guesses and display it at the end.

Add a check to verify that the length of the guess is the same as the length of the secret word. If it is not, display a message. If they are the same, then proceed to give the hint.

Make sure to account for the following in your hints:

Letters that are not present at all in the secret word (underscore _).

Letters that are present in the secret word, but in a different spot (lowercase).

Letters that are present in the secret word at that exact spot spot (uppercase).

Until now my code looks like this:

I don’t know how to do last parts of the code, the lower.case, upper.case hints, and the error message displayed if the user types the wrong amount of letters.

If someone can help me with this, I will be grateful !

Try this:

if len(guess) != len(secret_word):
    print("The word is not the right length!")

The len() function returns the length of the string.

There is a lower() function for strings.

"ABCD".lower() returns "abcd"

1 Like

Thanks for that tip, what about the hints part:
Letters that are present in the secret word, but in a different spot (lowercase).

Letters that are present in the secret word at that exact spot spot (uppercase).

Do you have any tips for that?

Sets: Built-in Types — Python 3.11.0 documentation

Cheers,
Cameron Simpson cs@cskk.id.au

if inputed_word.lower() in secret_word and not inputed_word == secret_word:
print("The word is inside, but lowercase")

elif inputed_word.upper() in secret_word and not inputed_word == secret_word:
print("The word is inside, but uppercase")

I may not be understanding your question correctly. But in this code, replace inputed_word with the word the user imputed and secret_word with the secret word. I don’t have access to your code right now, I’m on email.

It’s supposed to work like this: