Python Playground

Print in a Function & String Formatting

Learn how to use print() inside a function and how to format strings in Python using f-strings, .format(), and % formatting.

Python idle

Run the code first so AI Tutor can see the latest output or error.

Python Playground

Print in a Function & String Formatting

Learn how to use print() inside a function and how to format strings in Python using f-strings, .format(), and % formatting.

Python idle

Run the code first so AI Tutor can see the latest output or error.

Python Playground

Print in a Function & String Formatting

Learn how to use print() inside a function and how to format strings in Python using f-strings, .format(), and % formatting.

Python idle

Run the code first so AI Tutor can see the latest output or error.

Python Challenge

Draw a Grid with Print

Write a function called draw_grid that prints a 2×2 grid that looks exactly like this:

+ - - - - + - - - - +
|         |         |
|         |         |
|         |         |
|         |         |
+ - - - - + - - - - +
|         |         |
|         |         |
|         |         |
|         |         |
+ - - - - + - - - - +

Hints:

  • To print more than one value on a line, use a comma-separated sequence:
    print('+', '-')
  • By default, print moves to the next line. To stay on the same line, use end=' ':
    print('+', end=' ')
    print('-')
  • Think about which lines repeat — can you use a loop?
Python idle

Run the code first so AI Tutor can see the latest output or error.

Hints

Reference Solution

c7a1a4c3-4ec4-4022-8840-56dd9105eb69-1.jpg?height=216&width=983&top_left_y=1443&top_left_x=571