how can i make a russian roulette in simple python

0

I wanted a simple scrip where it counts up to 6 using while or another replay method. and will have a list with 5 flawed and 1 died and he counts up to 6 raffling this list and when he speaks died he wanted her to look like. but in my script it continues speaking until completing 6 loops

    def russa(self, message, name_sender, to=''):
     list_morte = ['Morreu','falho','falho','falho','falho','falho',]
     self.post(message='Vamos nós matar hehehe') 
     self.post(message='Go.!') 
     contador =0
     while (contador<6):
       time.sleep(3) #delay de 5 segundos
       self.post(message='/roll')
       list_morte = random.choice(list_morte)
       self.post('/me %s' % list_morte)
     contador =contador+1 
     if list_morte == 'Morreu':
        self.post(message='Morreu')
    
asked by anonymous 04.05.2018 / 01:58

1 answer

5

If you want the repetition to stop when the value "died" is drawn, simply make a conditional structure:

while contador < 6:
    print('atirando...')
    acao = random.choice(list_morte)
    print(acao)
    if acao == 'Morreu':
        break  # Aqui para o laço
    contador += 1

If the number of attempts has been undefined, as long as it stops when the action "died," the best would be put into an loop , using:

while True:
    acao = random.choice(list_morte)
    print(acao)
    if acao == 'Morreu':
        break

So the program will run until the action "died" is gone.

  

Note: You were overwriting the value of list_morte by doing list_morte = random.choice(list_morte) , which generated a very different output than expected, so I called acao return choice .

    
04.05.2018 / 02:13