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

Is there any way to create a user generator?

I need your help, I’m trying to create a program that can generate usernames by entering its first and lastname and apply some rules specifically, but I don’t know how to store a list of elements into a list on Python.


print('Welcome to your program!')
print("How many users do you want to create: ")

firstName = input('What is your firstname: \n').lower()
lastName = input('What is your lastname: \n').lower()

def username_gen(firstName, lastName):
    all_letters = firstName
    first_letters = lastName[0:3]

    username = '{}{}'.format(all_letters, first_letters)
    print(username +'company.com')

username_gen(firstName, lastName)

I can only create one user, and I would like to create more than 10 users.

Can anybody help me?

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

I tried using lists but it did not work, not sure If I did it correctly.

>Solution :

Put a loop around the process, and collect into a list

usernames = []
nb = int(input("How many users do you want to create ?"))
for i in range(nb):
    print(f"Person n°{i + 1}")
    firstName = input('What is your firstname: ').lower()
    lastName = input('What is your lastname: ').lower()
    username = username_gen(firstName, lastName)
    print(">>", username)
    usernames.append(username)
print(usernames)

Using f-string that is easier to build strings with variable

def username_gen(firstName, lastName):
    all_letters = firstName
    first_letters = lastName[0:3]
    return f'{all_letters}{first_letters}company.com'
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