Help in Python! Guessing game!

1

I need some help with this little game. The question is this, the game I've already done and it's working perfectly, what I really need is loop with While .

I can not find the error, as long as the user does not hit the value I need the game to continue until I reach the fifth attempt, though mine is not running while while and I can not understand why .

The following is the code below:

from random import randint


def acertou():

n = randint(1,11)

x = 0

print(n)


while (x < 5):

    x = x + 1
    y = int(input("Digite um número "))
    if n == y:
        return "Parabéns,você acertou!"
        break
    elif y > n:
        return "Opa,o número que você escolheu é maior que o sorteado!"
    return "Opa,o número que você escolheu é menor que o sorteado!"
    
asked by anonymous 10.11.2017 / 00:28

1 answer

1

Apparently, you want your function to return only if it hits, or err more than 5 times, but on the two end lines:

elif y > n:
    return "Opa,o número que você escolheu é maior que o sorteado!"
return "Opa,o número que você escolheu é menor que o sorteado!"

You are returning, you are leaving the function returning the text. the while does nothing, because it does not matter which path the code returns. (the break after the return also does not make sense, the return has already exited the whole function code)

Switch to a print and you will end the function only if you hit or miss more than 5 times.

obs: Assuming you are receiving data from the console.

    
10.11.2017 / 00:56