# Boucles while/else 8/19 Loops

#1

Hello,
I block the While / Else … I come back to the data but I have an error message.
I think the indentation is good so I do not understand …

Here is my code:

``````from random import randrange

nombre_aleatoire = randrange(1, 10)

nombre_aleatoire = 3
while nombre_aleatoire > 0:
guess = int(raw_input("Entrez un chiffre entre 1 et 9 :"))
if guess == nombre_aleatoire:
print "bravo"
break
nombre_aleatoire -= 1
else:
print "perdu"
``````

I manage to enter data (3 shots like asking …) then I have this error message:

Ooopps, thank you again. Remember to increment counts!

Thank you to those who can help me !

#2

You generate a random number we need to guess here:

``````nombre_aleatoire = randrange(1, 10)
``````

Then on this two lines:

``````nombre_aleatoire = 3
nombre_aleatoire -= 1
``````

you overwrite your random variable (`nombre_aleatoire`), this should be the remaining guesses (`opciones_restantes`), change the variable name

#3

I tried with another variable name without success …

``````from random import RandRange

Random Number RandRange = (1, 10)

number = 3
``````

The console offers me to play 3 times … is like asking until I win, then I have the same error message again.

#4

the variable shouldn’t be number = 3, it should be:

``````opciones_restantes = 3
``````

the variable name should be a match

#5

it does not work either …

``````from random import randrange

nombre_aleatoire = randrange(1, 10)

options_restantes = 3
while nombre_aleatoire > 0:
guess = int(raw_input("Entrez un chiffre entre 1 et 9 :"))
if guess == nombre_aleatoire:
print "bravo"
break
nombre_aleatoire -= 1
else:
print "perdu"
``````

#6

well, you obviously want to have options_restantes in your while loop:

``````while options_restantes > 0:
``````

and i would also reduce the options_restantes, not the randon mumber (`nombre_aleatoire`):

``````options_restantes -= 1
``````

Also, make sure all indent levels are correct

#7

I think I have good indentations … but I still have the same error message:

Thanks, thank you again. Remember to increment counts!

``````options_restantes = 3

while options_restantes > 0:
guess = int(raw_input("Entrez un chiffre entre 1 et 9 :"))
if guess == nombre_aleatoire:
print "bravo"
break
options_restantes -= 1
else:
print "perdu"``````

#8

This line is wrongly indented:

``````options_restantes -= 1
``````

now, remaining options (`options_restantes`) only gets reduced if the user guess the correct number.

#9

or do I indent it?
I tested several indentations that gives me an error on the else an indentation error
options_restantes - = 1

#10

It should be outside the if statement:

``````options_restantes = 3

while options_restantes > 0:
guess = int(raw_input("Entrez un chiffre entre 1 et 9 :"))
if guess == nombre_aleatoire:
print "bravo"
break
options_restantes -= 1
else:
print "perdu"
``````

#11

be outside?
Like this?
(It still does not work)

``````options_restantes = 3

while options_restantes > 0:
guess = int(raw_input("Entrez un chiffre entre 1 et 9 :"))
if guess == nombre_aleatoire:
print "bravo"
break

options_restantes -= 1
else:
print "perdu"
``````

#12

What have you done this time? Here is the correct code:

``````from random import randrange

numero_aleatorio = randrange(1, 10)

opciones_restantes = 3

while opciones_restantes > 0:
opcion = int(raw_input("Entrez un chiffre entre 1 et 9 :"))
if opcion == numero_aleatorio:
print "Ganaste!"
break

opciones_restantes -= 1
else:
print "Perdiste"
``````

i am so done, you print wrong things, many variable names do not match, you seem to be using a weird mixture of english and spanish words, that is not going to work. There are countless mistakes, i keep finding more and more and more. This is just endless

#13
``````from random import randrange

nombre_aleatoire = randrange(1, 10)

options_restantes = 3

while options_restantes > 0:
options = int(raw_input("Entrez un chiffre entre 1 et 9 :"))
if options == nombre_aleatoire:
print "bravo"
break

options_restantes -= 1
else:
print "perdu"
``````

Same error message:
Oopss, thank you again. Remember to increment counts!

(I use google translation to translate forum posts because I do not find in French…)

#14

It seems i put the wrong words into google translate, i thought you did the spanish course, did you find it strange i used spanish words…?

#15

I understood not

I already did the Spanish (a long time ago ^^)

#16

Then why do the french now? The french instructions are poor, what on earth should be used as variable name for the counter?

#17

I give up, sorry to have bothered you. Create a new topic so someone who is capable of helping you can help you

#18