← All Exercises

Python String Formatting

basicpython~10min

Background

String formatting is essential for user-facing output, reports, logs, and data presentation in Python applications.

Problem

Write a function that takes a name, price, and quantity and returns a formatted receipt line using f-strings with proper alignment and precision.

Input

A string name, a float price, and an integer quantity.

Output

A formatted string showing the item, unit price, and total cost.

Sample tests

Sample 1

Input: "Widget", 9.99, 3
Expected: "Widget    $9.99 x 3 = $29.97"

Your solution

Learning objective

Learn f-string formatting with alignment, precision, and expression interpolation.