lundi 31 mai 2021

Problem with a variable and IF statements [closed]

So, I am working on editing a program in which the user has to guess a scrambled word.

I'm trying to edit in a part where the computer asks the user if they would like a hint, and then the program prints the hint, but I also would like to incentivise the player for not taking the hint.

So, I've got 2 variables I am trying to edit in, hint, and hintinput.

This is the code I've got so far:

while guess != correct and guess != "":
    print("Sorry, that's not it.")
    if hint == False:
        hintinput = print("Would you like a hint? Y/N.")
        if hintinput == "Y":
            print("Your hint is: ")
            print(word[0])
            print(word[1])
            print(word[2])
            hint = True
            guess = input("Your guess: ") 
        elif hintinput == "N":
            guess = input("Your guess: ")
    else:
        guess = input("Your guess: ")

The code is designed to ask so that if the player fails to correctly answer the question correctly and the player hasn't taken a hint, the computer will ask the player if they want a hint.

If the player wants the hint, the computer prints out the hint and then switches the hint to True, so the player won't be asked again for the hint if they get it wrong.

I tried to do this with the following code:

# create a jumbled version of the word, along with setting the hint variables to False. 
jumble =""
hintinput =""
hint =""

The last 2 lines of code I've added so that the game starts with the assumption that the player has not taken the hint.

However, when I run the code and get the question wrong, the computer doesn't ask me about the hint.

What should I do to fix this?

Aucun commentaire:

Enregistrer un commentaire