samedi 13 juin 2020

Choose a random string from a list as many times as a length of a variable

Code:

if Dash == 0:
    # Enter X multiple times
    print("Only use X")
    Code0 = input()
    print(secrets.choice(LetterNumbers) * len(Code0))

The variable "LetterNumbers" is a list that contains all english letters and numbers. Everything works, except this:

print(secrets.choice(LetterNumbers) * len(Code0))

It chooses a random letter or number from "LetterNumbers" should do that as many times as the length of the variable "Code0", but it only chooses one (for example A) and then it prints the same one just as many times as the length of "Code0".

The output is :

AAA

But it should be:

ABC (or anything random but not the same Letter everytime)

I hope you can understand what I am trying to say, because I don't speak english very well.

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire