pygame : while runs once and stops

Viewed 26

I want to make a program that draw six number. please help me. When (A)button is pressed, it runs once and stops. What should I do if I want to run it many times?

numT = []
team = random.randint(1, 6)  

if event.type == pygame.KEYDOWN:
    if event.key == event.key == ord('a'):
        for i in range(6):
            while team in numT:
                team = random.randint(1, 6)
            numT.append(team)

        num1 = font.render(str(numT), True, (255, 255, 255))

screen.blit(num1, (200, 117))

The result that I want(on the pygame screen) : example

[1, 3, 5, 2, 6, 4]
1 Answers

If you want to generate a new sequence, you have to clear the old one with numT = [] or numT.clear().
However, the conde can be simplified using random.shuffle():

if event.type == pygame.KEYDOWN:
    if event.key == pygame.K_a:
        numT = list(range(1, 7))
        random.shuffle(numT)
        num1 = font.render(str(numT), True, (255, 255, 255))     
Related