mardi 15 septembre 2015

How do I generate non-repeating random numbers in a while loop? (Python 3)

So far what I have is

import random
def go():
    rounds = 0
    while rounds < 5:
        number = random.randint(1, 5)
        if number == 1:
            print('a')
        elif number == 2:
            print('b')
        elif number == 3:
            print('c')
        elif number == 4:
            print('d')
        elif number == 5:
            print('e')
        rounds = rounds + 1
go()

and the output ends up beings something along the lines of

e
e
c
b
e

How do I make it so a number is only used once and the letters do not repeat? (ex. something like)

a
e
b
c
d

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire