Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Generating random strings based on user input

I am a complete beginner in Python and I want to generate a random string based on user input for a password generator I currently have the below:

import random
import string

print("Password Generator")


def lower(length):
    lower_case = string.ascii_lowercase
    generate = ''.join(random.choice(lower_case) for i in range(length))


amount_of_characters = input("How many characters do you want?")

I want the input of the user to equal the length of the random string.

For example if the user inputted 36 the string generated is 36 characters long.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

import random
import string

print("Password Generator")


def gen(length):
    lower_case = string.ascii_lowercase
    generate = ''.join(random.choice(lower_case) for i in range(length))
    return generate


amount_of_characters = int(input("How many characters do you want?"))
print(gen(amount_of_characters))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading