mercredi 14 juillet 2021

How do you pad a string to a length = n with consecutivley randomly generated characters in python?

I'm trying to take a user input string, the string cannot be over 70char's from the user but once padded, the total string will be 100chars in length.

However, i must make up the rest of the 100chars of the string using randomly generated letters. My issue i'm having is that I'm generating the same singular character and then padding it to meet the 100char limit. How do I make it so that the string contains random characters?

Example of what i want: user input: ABC

desired output: ABCJ4RLKDIJHSJRLWOINGHZXNROQUTJHLOUHFPSNDUVMFHTQAQ etc upto 100 chars

What i'm getting is the following:

user input: ABC

output: ABCTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT etc upto 100 chars.

here is my code

text = input("Enter your string: ")
if len(text) > 70: exit("Char limit cannot exceed 70")

print(text.ljust(100, random.choice(string.ascii_letters)))



Aucun commentaire:

Enregistrer un commentaire