Problem like Python hangman game

Asked

Viewed 59 times

-1

I’m doing a hangman game in Python, the user writes the word and then the tip, another user will play the game and can choose between play or ask for a hint but when returning the variable tip it does not print and jumps to the next question, how can I recover the variable inside the while

while dicas > 0:
menu = input("Digite 1 para Jogar ou 2 para Solicitar dica: ")
if(menu == 1):
    letra = str.lower(input("Digite uma letra: "))

    for i in range(0, len(palavra)):
        if letra == palavra[i]:
            letras_descobertas[i] = letra
            errou = False


    print(letras_descobertas)
    for x in range(0, len(letras_descobertas)):
        if letras_descobertas[x] == "*":
            acertou = False

    if errou == True:
        vida = vida -1
        print("Você errou! Você possui ", vida, "vidas.")

        if vida <= 0:
            print("Suas vidas acabaram!")
           
if(menu == 2):
    if(dica1 == str):
        print(dica1)
        dica1 = 0
    elif(dica2 == str):
        print(dica2)
        dica2 = 0
    elif(dica3 == str):
        print(dica3)
        dica3 = 0
dicas = dicas -1

full code here (https://pastebin.com/print/WSs4dLGL)

1 answer

0


The input always returns a string vc must last an int() to convert to integer, so it becomes comparable; Other than that whenever you hit a letter 1 and dps made a mistake he made no mistake since the Error variable did not have its value turned to True, I put it in the beginning of while; tbm the tips = tips -1 was with identation error. I have not understood the str, besides that it did not work, in the tips so I put another way.

while dicas > 0:
errou = True
menu = int(input("Digite 1 para Jogar ou 2 para Solicitar dica: "))
if(menu == 1):
    letra = str.lower(input("Digite uma letra: "))

    for i in range(0, len(palavra)):
        if letra == palavra[i]:
            letras_descobertas[i] = letra
            errou = False


    print(letras_descobertas)
    for x in range(0, len(letras_descobertas)):
        if letras_descobertas[x] == "*":
            acertou = False

    if errou == True:
        vida = vida -1
        print("Você errou! Você possui ", vida, "vidas.")

        if vida <= 0:
            print("Suas vidas acabaram!")
            
if(menu == 2):
    if(dicas == 3):
        print(dica1)
        dica1 = 0
    elif(dicas == 2):
        print(dica2)
        dica2 = 0
    elif(dicas == 1):
        print(dica3)
        dica3 = 0
    dicas = dicas -1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.