Editor

Create a Formatted Table Row

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 lesson

Create three variables: name = "Alice", score = 95.8, and grade = "A+". Print a formatted table row where:

  • The name is left-aligned in a 10-character-wide field
  • The score is right-aligned in an 8-character-wide field with 1 decimal place
  • The grade is center-aligned in a 6-character-wide field
  • Expected output (the | characters are part of the output):

    | Alice      |     95.8 |   A+  |
    # Create the variables and print the formatted table row

    More String Formatting exercises

    All Python exercises · 50 practice problems · Python Fundamentals quiz