-2

Write a Python program that takes the user's name as input and displays and welcomes them.

Expected behavior:

Enter your name: John
Welcome John

The Python code for taking the input and displaying the output is already provided

#take the user's name as input
name = input("Enter your name: ")
print(name)



#the vaiable that includes the welcome message is alredy provided.
#Please complete this part using the knowledge obtained in this lesson.
greeting = ("Welcome John")


#print the welcome message
print(greeting)

Out put I got with one error

2

4 Answers 4

1
greeting = (f' Welcome {name}')

Or

greeting = ('Welcome ' + name )
Sign up to request clarification or add additional context in comments.

1 Comment

You should include details as to why this fixes the poster's issue and what the code examples do.
0

The problem I see is an error in your code where you have hard coded the name "John" with the output. What you ought to do instead, is to output the Variable alongside the greeting message.

greeting = (f"Welcome {name}")

Using this will output the welcome message alongwith the name that's entered. What I have done is used an F-string however there's other ways to do it as well. Hope that answer's your question.

2 Comments

Could you please give me some more details to fix because I am a beginner for python
What more details do you need? You are simply printing the line Welcome John and you intend to print the user input instead of the word "John" which can only be done through a variable and either f-string literals or string concatenations.
0

You have hard coded the greeting

greeting = ("Welcome John")

Given you have a name the user has provided, you can use string formatting to interpolate that name into your greeting like this:

greeting = (f"Welcome {name}")

(Notice, you put the variable in curly braces)

Comments

0
# take the user's name as input
name = input("Enter your name: ")
print(name)

# Please complete this part using the knowledge obtained in this lesson.
greeting = ("Welcome" +" "+ name)

# print the welcome message
print(greeting)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.