Is there any way to create a user generator?

Question:

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?

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

Asked By: Israel Padilla

||

Answers:

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'
Answered By: azro
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.