Format a Receipt Line
Beginner · Write the code · 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 lessonCreate variables item set to "Cappuccino" and price set to 4.5. Then use an f-string to print a receipt line in this exact format:
Cappuccino .......... $4.50The item name should be left-aligned and the price should show exactly 2 decimal places. Use the string " .......... $" between the name and price.
# Create the variables and print the formatted receipt line
More String Formatting exercises
- Format a Large Number with CommasBeginner
- Create a Formatted Table RowBeginner
- Fix the Broken f-stringBeginner
- Generate a Personalized Email GreetingBeginner
All Python exercises · 50 practice problems · Python Fundamentals quiz