+ 2
Can someone show me solution to this I got stuck
# Take the name as input name = input() # Use concatenation to join 2 strings message = "Nice to meet you, " name # Display the message to the user
3 Réponses
+ 1
Concatenation is when 2 strings are joined together to make a personalised output, such as "Hello Souleymane". When concatenating 2 strings together, you need to ensure that both values are strings, as if one of them is a number, then the program will output an error. You can concatenate strings, using 2 methods. The first method is to concatenate the strings, by writing the value you want to show, meaning that the the program will not concatenate the user's input, with the string, such as:
message = "Hello" + "Souleymane"
#Output
Hello Souleymane
The second method is to concatenate the string, so that you can create personalised messages. In this method, make sure to ask the user for input, and store that in a variable, and then, use it wherever you want to use, in the program, after the variable declaration, such as:
name = input()
message = "Hello" + name
#input
Test
#Output
Hello Test
You can concatenate as many strings as you want, in Python.
+ 2
To join 2 strings you must use what is called concatenation which is what i see you said in your comments, but didnt implement it correctly. To use concatentation you have to use a + sign i would suggest looking at https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_strings_concatenate.asp
+ 2
To display the personalised message in Python, write:
print(message)
Please learn Python basics, by taking introduction to Python course on Sololearn:
https://www.sololearn.com/learn/courses/python-introduction