Randomize letters

-2

I know how to generate numbers, but how do I type letters like AB BC AEEE , for example.

import random

import string

for j in range(40,100):

print(random.choice(string.ascii_uppercase))

In this code I generate a lowercase letter. Accurate 4 letters per class number of classes is between 40 to 100

    
asked by anonymous 10.07.2018 / 01:01

1 answer

2

What you need to do is basically call the random.choice function the number of times you want to draw a letter. How do you need 4 letters: 4 times.

import random
import string

letras = string.ascii_uppercase

for turma in range(40, 100):
    codigo = ''.join(random.choice(letras) for _ in range(4))
    print('Turma', turma, 'possui o código', codigo)

However, this does not guarantee that the codes will be unique, and two or more classes may have the same code.

    
10.07.2018 / 01:16