Home > OS >  Which variable should I use on Python to uppercase results in type word guessing game
Which variable should I use on Python to uppercase results in type word guessing game

Time:06-26

I'm writing a word guessing game like, what I'm expecting is that results appear in uppercase when is on the right spot. Until now, I write the program and it completely works but, let me show you... This is how it goes:

print("Welcome to the word guessing game!")
print(" ")
secret_word = "heaven"
guess_count = 0
display = '_'*len(secret_word)

(len(secret_word)-1)
word = ["_"] * len(secret_word)
while True:
    guess = input("What is your guess? ")
    for i in range(len(secret_word)):
        if guess == secret_word[i]:
            word[i] = guess
    if guess == secret_word:
        print("")
        print("You guessed it!")
        break
    else:
        print("".join(word))
        guess_count = guess_count 1

print(f"It took you {guess_count} guesses")

So, I'm not sure where to put the uppercase function. Since the letters are not present at all in the secret word, it shows an "_". The letters that are present in the secret word, but in a different spot should be shown as lowercase. The Letters that are present in the secret word at that exact spot, shown in uppercase.

I tried to find the answer on YT and other sites without success. I just want to understand which functions using (.uppercase) I can use to make it. Hope you can help me, guys. Thanks in advance!

CodePudding user response:

I do not understand. In your code, it seems as though the guess is a single character, but you do not ask for the spot which is needed to determine if it must be uppercase or lowercase. I tried to answer your question based on wordle, so I guessed the player would have to enter a word. You'd need something like:

for i in range(len(secret_word)):
    if guess[i] = secret_word[i]:
        word[i] = guess[i].upper()
    elif guess[i] in secret_word:
        word[i] = guess[i].lower
  • Related