67.7k views
5 votes
Write a program that asks the users to input his/her last name first, then first name. Display a new user name which is the first letter of the user’s first name plus last name and a random number between 1 and 10.

1 Answer

4 votes

Answer:

import random

last_name = input("Enter last name: ")

first_name = input("Enter first name: ")

number = random.randint(1, 10)

user_name = first_name[0] + last_name + str(number)

print(user_name)

Step-by-step explanation:

*The code is in Python.

import the random to generate a random number

Ask the user to enter the last_name and first_name

Generate a random number between 1 and 10 using randint() method

Set the user_name as first letter of the first name (use indexing, the item in the index 0 is the first letter) and last name and the number you generated

Print the user_name

User WTP
by
5.5k points