Tu propia sentencia while / else // Your own while / else sentence


#1

Hi everybody,
Sorry this is in Spanish, it should be the same for you, but the thing is: after giving it 3 options, it keep asking me for inputs, and then it never works. Don't know how to fix it :frowning:

from random import randint

genera un nĂºmero del 1 al 10 inclusive

numero_aleatorio = randint(1, 10)

opciones_restantes = 3

while opciones_restantes > 0:
opcion = int(raw_input("Tu opcion: "))
if opcion == numero_aleatorio:
print "¡Ganaste!"
break
else:
print "Perdiste"
opciones_restantes -= 1

Replace this line with your code.

`


#2

Hey @blogace15733,
why don't set it up upside-down with a little change?

numero_aleatorio = randint(1, 10)

opciones_restantes = 0

while True:
    opcion = int(raw_input("Tu opcion :"))
    if opciones_restantes === 3:
        print "Fail"
        break
    elif opcion == numero_aleatorio:
        print "¡Ganaste!"
        break
    else:
        print "Perdiste"
        opciones_restantes += 1

Hope this will help - maybe :slight_smile:


#3

Nope, I don't think so. But thanks.