6
respostas

Erro na line 9

Fiz o programa igual do professor, mas ele da erro na linha do while e não sei o que está errado, já revisei o codigo todo e não achei.

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

6 respostas

Olá Lucca, tudo bem?

Cola seu código aqui, por favor.

print("*******************************")
print("Welcome to the guessing game !!")
print("*******************************")

secret_number = 77
attempts = 3
rounds = 1

    while (rounds <= attempts):
        print("Attempt {} im {}".format(rounds,attempts))
        kick_str = input ("Enter your number:")
        print("You typed:" , kick_str )
        kick = int(kick_str)

hit = secret_number == kick
larger = kick > secret_number
smaller = kick < secret_number

if(hit):
    print("You're right !!")
else:
    if(larger):
         print("You missed! Your guess was higher than the secret number.")
    elif(smaller):
        print("You missed! Your guess was less than the secret number.")

        Rounds = Rounds + 1

print("End of the game !!")

Olá Lucca, a identação do seu código está errado, tenta assim:

print("*******************************")
print("Welcome to the guessing game !!")
print("*******************************")

secret_number = 77
attempts = 3
rounds = 1

while (rounds <= attempts):
    print("Attempt {} im {}".format(rounds,attempts))
    kick_str = input ("Enter your number:")
    print("You typed:" , kick_str )
    kick = int(kick_str)

hit = secret_number == kick
larger = kick > secret_number
smaller = kick < secret_number

if(hit):
    print("You're right !!")
else:
    if(larger):
         print("You missed! Your guess was higher than the secret number.")
    elif(smaller):
        print("You missed! Your guess was less than the secret number.")

        Rounds = Rounds + 1

print("End of the game !!")

Funcionou,obrigado. O que estava errado ?

estava:

    while (rounds <= attempts):
        print("Attempt {} im {}".format(rounds,attempts))
        kick_str = input ("Enter your number:")
        print("You typed:" , kick_str )
        kick = int(kick_str)

o correto é:

while (rounds <= attempts):
    print("Attempt {} im {}".format(rounds,attempts))
    kick_str = input ("Enter your number:")
    print("You typed:" , kick_str )
    kick = int(kick_str)
Ok. Obrigado