Skip to content

Generates unique usernames by combining the first initial, first 7 characters of the last name, and a random number, ensuring uniqueness by checking against a set of existing usernames.

Notifications You must be signed in to change notification settings

qtle3/u_name_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Username Generator

Overview

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.

  1. User Input:

    • The program prompts the user to enter their first name and last name in all lowercase letters.
  2. 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.
  3. 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.

Key Concepts

  • 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.

Usage

To run the program, execute the following command in your Python environment:

python generate_username.py

About

Generates unique usernames by combining the first initial, first 7 characters of the last name, and a random number, ensuring uniqueness by checking against a set of existing usernames.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages