Execise 1

Write a program in Python language that asks the user to enter their name and display their name with a welcome message!

Solution

Here's a simple Python program that asks the user for their name and displays a welcome message with their name:



# Ask the user to enter their name
name = input("What is your name? ")
# display  welcome ! message to the user 
print("Welcome, " + name + "!")
  • When the program runs: it will display a message asking the user to enter their name.
  • Once the user enters their name and presses Enter: the program will use the input() function to read the name and store it in the name variable.
  • The program will then use the print() function: to display a welcome message with the user's name, using string concatenation to combine the "Welcome, " and "!" strings with the name variable.

You can save this code in a file with a .py extension and run it from the command line or an IDE. When you run the program, it will ask for the user's name and display a personalized welcome message.

One thought on “Solution Exercise1: display welcome message to the user”

Leave a Reply