Combining Text in Python
Numbers can be added together.
But text behaves differently.
When you use the + operator with text, Python joins the pieces together instead of performing maths.
But text behaves differently.
When you use the + operator with text, Python joins the pieces together instead of performing maths.
This process is called concatenation.
Concatenation simply means:
Joining pieces of text into one larger sentence.
Concatenation simply means:
Joining pieces of text into one larger sentence.
Example:
Level 60
title = "Level " number = "60" result = title + number print(result)Output:
Level 60
Notice that if we want spacing between words, we must include the space ourselves.
For example:
For example:
word1 = "Death" word2 = "Knight" print(word1 + " " + word2)
In World of Software Engineering, we now have two players in a 1v1 fight!
We need to tell each player how much health they have remaining.
We need to tell each player how much health they have remaining.
Your Task:
1. Use string concatenation to print Player 1's health.
2. Use string concatenation to print Player 2's health.
The final output should read exactly:
Player 1 you have 1200 health
Player 2 you have 1100 health
1. Use string concatenation to print Player 1's health.
2. Use string concatenation to print Player 2's health.
The final output should read exactly:
Player 1 you have 1200 health
Player 2 you have 1100 health
Use string concatenation
sentence_start = "You have " sentence_end = " health" player1_health = "1200" player2_health = "1100" # Don't edit above this line print() print()