Fix the Broken f-string
Beginner · Fix the bug · from Python String Formatting: f-strings, format(), and % Operator
From the lesson: Python String Formatting: f-strings, format(), and % Operator
Imagine you're building a receipt for a coffee shop. You need to combine a product name, a price, and a quantity into one clean line. You could glue strings together with +, but it gets messy fast.
Read the lessonThe code below is supposed to print "Hello, Sam! You scored 92.5%." but it has bugs. Find and fix them.
There are 2 bugs to fix.
name = "Sam"
score = 0.925
print("Hello, {name}! You scored {score:.1%}.")
More String Formatting exercises
- Format a Receipt LineBeginner
- Format a Large Number with CommasBeginner
- Create a Formatted Table RowBeginner
- Generate a Personalized Email GreetingBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz