Editor

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 lesson

The 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

All Python exercises · 50 practice problems · Python Fundamentals quiz