This program generates a unique username based on the user's first and last names. The username is constructed by combining the first initial of the first name, the first seven characters of the last name, and a random three-digit number. It ensures that each username is unique by checking against a set of already used usernames.
-
User Input:
- The program prompts the user to enter their first name and last name in all lowercase letters.
-
Username Generation:
- The first initial of the first name is concatenated with the first seven characters of the last name.
- A random three-digit number is generated by adding two random integers between 1 and 10.
- The generated parts are concatenated to form the username.
-
Uniqueness Check:
- The program checks if the generated username is already in use by looking it up in a set of existing usernames.
- If the username is unique, it is added to the set and confirmed as available.
- If the username is not unique, the program recursively generates a new username.
- User Input: Collecting data from the user using
input()
. - String Manipulation: Combining initials, substrings, and random numbers to form usernames.
- Random Number Generation: Using
random.randint()
to create random numbers. - Sets: Utilizing a set to store and check for unique usernames.
- Recursion: Implementing recursion to handle cases where a generated username is already in use.
To run the program, execute the following command in your Python environment:
python generate_username.py