1
I need some help in this little game. The point is this, the game I’ve made and it’s working perfectly, what I need actually is the loop with the While.
I can not find the error, while the user does not hit the value I need the game to continue until the fifth attempt, however mine is not running the while and I can’t understand why.
Follow 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!"
Tip: arrange the indentation of your code. In Python it is fundamental and needs to be correct. Who knows the code works? Another tip: you have a function (
acertou()
) who will need to be called by someone.– Luiz Vieira