Solution: Concatenating Strings
Review the solution to the challenge.
We'll cover the following
Solution
- Ask the user for their first and last name. Store the value entered by the user in a variable called
firstName
andlastName
, respectively.
firstName = user_input first name
lastName = user_input last name
- Concatenate the
firstName
andlastName
variables with the greeting message"Hello, "
and an exclamation point using the string concatenation operator+
. Store the result in a variable calledgreeting
.
greeting = "Hello, " + firstName + " " + lastName + "!"
- Concatenate the
lastName
variable with the message"How are you doing"
and a question mark using the string concatenation operator+
. Store the result in a variable calledinquiring_health
.
inquiring_health = "How are you doing " + lastName + "?"
- Finally, print the
greeting
andinquiring_health
variables.
print greeting
print inquiring health
Below is the complete pseudocode for this challenge:
Get hands-on with 1400+ tech skills courses.