
Python Program to Generate Unique Nicknames
Python Mini Projects
Instructions
In this Python project you will have to build a Python program to generate unique nicknames. The script will ask the user’s first name as input and generate a unique nickname based on the given name. The nickname should be a combination of the user’s first name and a randomly generated number. It is a very useful Python project since you can run it on a regular basis whenever you need to create a new login account.
Steps
- Take input from the user for their first name.
- Generate a random number using the
"random"module in Python. - Combine the user’s first name with the generated random number to create a nickname.
- Print the generated nickname as the output.
Solution
import random
def generate_nickname(first_name):
random_number = random.randint(0, 100) # Generate a random number between 0 to 100
nickname = first_name + str(random_number) # Combine the first name with the random number
return nickname
# Take user input
first_name = input("Enter your first name: ")
# Generate and print the nickname
nickname = generate_nickname(first_name)
print("Your nickname is:", nickname)
Expected Output
Enter your first name: david ## Ouptut Your nickname is: david62