Printing Dynamic Information
In World of Software Engineering, our character (above) is:
Snowcurse is currently collecting ogre skulls.
name = "Snowcurse"
level = 60
class_type = "Warlock"
Snowcurse is currently collecting ogre skulls.
Sometimes we want to print sentences that include variable values.
For example:
If we want to say how many skulls were collected, we could combine text and variables.
For example:
ogre_skulls = 5
If we want to say how many skulls were collected, we could combine text and variables.
This is where f-strings help.
An f-string lets you place variables directly inside a sentence.
Example:
The f before the quotation marks tells Python:
"Insert variable values into this sentence."
Anything inside curly brackets
An f-string lets you place variables directly inside a sentence.
Example:
print(f"Snowcurse has collected {ogre_skulls} ogre skulls.")The f before the quotation marks tells Python:
"Insert variable values into this sentence."
Anything inside curly brackets
{ } gets replaced with its value.
Without an f-string, Python would just print the words exactly as written.
With an f-string, Python swaps the variable name for its actual value.
With an f-string, Python swaps the variable name for its actual value.
Your Task:
Fix the bug in the code below.
• Print out the character name, level and class as a sentence
• e.g. Kris is a level 70 warrior
Use f-strings correctly!
Fix the bug in the code below.
• Print out the character name, level and class as a sentence
• e.g. Kris is a level 70 warrior
Use f-strings correctly!
Fix the f-string
name = "Snowcurse"
level = 60
class_type = "Warlock"
# Don't edit above this line
print("NAME is a level LEVEL CLASS")