jeudi 9 juillet 2020

How do I put a set of random letters into an aligned string in python 3?

I'm trying to create a random set of letters and put it inside a string, and I'm using python 3.6 here (I have tested some other ways to do this, but they are outdated and only work in the earliest versions of python 3 and below).

I am using this:

import random
import string

randomletters = random.sample(string.ascii_letters, 4)
for randomletters in randomletters: # gather the elements into a string
    stringofrndletters = "".join(randomletters)
    print(stringofrndletters)

The output looks like:

>> print(stringofrndletters)
r
B
X
g

But I want the output to be similar to this:

>> print(stringofrndletters)
rBXg



Aucun commentaire:

Enregistrer un commentaire