Python · Python Fundamentals

Pattern Printing — Practice Questions

50 questions. Try each one yourself before checking the answer.

Q1StarsEasy

Print a single row of 5 stars: * * * * *

Q2StarsEasy

Print a square of stars, 4 rows by 4 columns.

* * * *
* * * *
* * * *
* * * *
Q3Stars — PyramidEasy

Print a left-aligned star pyramid with 5 rows.

*
* *
* * *
* * * *
* * * * *
Q4Stars — Inverted PyramidEasy

Print an inverted left-aligned star pyramid with 5 rows.

* * * * *
* * * *
* * *
* *
*
Q5NumbersEasy

Print a number pyramid where each row repeats its own row number.

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Q6NumbersEasy

Print an increasing-count number pyramid.

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Q7AlphabetsEasy

Print the uppercase alphabet letters A through E, one per row, using chr() and ord().

A
B
C
D
E
Q8AlphabetsEasy

Print an alphabet pyramid using letters starting from A.

A
A B
A B C
A B C D
A B C D E
Q9Pattern LogicEasy

Print a right-aligned staircase of stars using spaces plus stars, 5 rows tall.

        *
      * *
    * * *
  * * * *
* * * * *
Q10Hollow PatternsEasy

Print a hollow square (border only) of size 5x5 using stars.

* * * * *
*       *
*       *
*       *
* * * * *
Q11Stars — PyramidMedium

Print a centered star pyramid (a proper triangle, not left-aligned) with 5 rows.

    *
   * *
  * * *
 * * * *
* * * * *
Q12DiamondMedium

Print a full star diamond with 5 rows on top and 5 on the bottom (centered).

    *
   * *
  * * *
 * * * *
* * * * *
 * * * *
  * * *
   * *
    *
Q13NumbersMedium

Print a number pyramid that counts down within each row instead of up.

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
Q14AlphabetsMedium

Print an inverted alphabet pyramid, 5 rows, shrinking from ABCDE down to A.

A B C D E
A B C D
A B C
A B
A
Q15Hollow PatternsMedium

Print a hollow triangle (border only) with 5 rows.

*
* *
*   *
*     *
* * * * *
Q16NumbersMedium

Print a pyramid where each row repeats the row number in reverse (row i prints i repeated i times, but on the last row it should read 5 5 5 5 5, on the second-to-last 4 4 4 4, etc. — an inverted number square-pyramid).

5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Q17Pattern LogicMedium

Print a "butterfly" pattern's top half only, 5 rows, using stars on the outside and spaces in the middle.

*         *
* *     * *
* * * * * *
Q18NumbersMedium

Print a diamond-shaped number pattern using row numbers (top half increasing, bottom half decreasing), 5 rows each half.

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Q19AlphabetsMedium

Print a centered alphabet pyramid using letters A through E.

        A
      A B
    A B C
  A B C D
A B C D E
Q20Hollow PatternsMedium

Print a hollow diamond (border only) with 5 rows on top and 5 on the bottom.

    *
   * *
  *   *
 *     *
*       *
 *     *
  *   *
   * *
    *
Q21Pascal's TriangleMedium

Print the first 5 rows of Pascal's triangle by computing each row from binomial coefficients (row[j] = row[j-1] * (i - j) / (j + 1)).

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Q22Pattern LogicMedium

Print an "X" pattern made of stars in a 5x5 grid.

*       *
  *   *
    *
  *   *
*       *
Q23NumbersMedium

Print a multiplication-table-style triangle where row i shows i * 1 through i * i.

1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
Q24Real-WorldMedium

Ask the user how many rows they want, then print a left-aligned star pyramid of that size.

Q25Real-WorldMedium

Ask the user for a single character and how many rows, then print a centered pyramid of that character instead of *.

Q26Pattern LogicMedium

Print a checkerboard-style pattern of * and space alternating, 5x5.

* * * * *
 * * * *
* * * * *
 * * * *
* * * * *
Q27NumbersMedium

Print a "floating point" number triangle where each row shows the row number divided by increasing values (formatted to 2 decimals).

1.00
2.00 1.00
3.00 1.50 1.00
Q28AlphabetsMedium

Print each row of a pyramid using the SAME repeating letter per row, advancing the letter each row (row 1 = A, row 2 = BB, row 3 = CCC, ...).

A
B B
C C C
D D D D
E E E E E
Q29Hollow PatternsMedium

Print a hollow rectangle, 4 rows by 8 columns.

* * * * * * * *
*             *
*             *
* * * * * * * *
Q30Pattern LogicMedium

Print a right-triangle of numbers where each row restarts the count from 1, but the row length grows (like Q6), formatted with a border of # above and below.

##########
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
##########
Q31DiamondHard

Print a hollow diamond made of numbers instead of stars, where each border cell shows the row number.

    1
   2 2
  3   3
 4     4
5       5
 4     4
  3   3
   2 2
    1
Q32NumbersHard

Print Pascal's triangle centered (each row indented so the whole shape looks like a real triangle), for 6 rows.

          1
        1   1
      1   2   1
    1   3   3   1
  1   4   6   4   1
1   5  10  10   5   1
Q33Pattern LogicHard

Print an hourglass pattern of stars, 5 rows on top narrowing to a point, then 5 rows widening back out.

* * * * *
 * * * *
  * * *
   * *
    *
   * *
  * * *
 * * * *
* * * * *
Q34NumbersHard

Print a triangle where each row alternates between counting up and counting down based on whether the row number is odd or even.

1
2 1
1 2 3
4 3 2 1
1 2 3 4 5
Q35AlphabetsHard

Print a pyramid where each row is a palindrome built from ascending letters (row 3 = A B C B A).

A
A B A
A B C B A
A B C D C B A
A B C D E D C B A
Q36Hollow PatternsHard

Print a hollow hourglass (border-only version of Q33), 5 rows narrowing then 5 widening.

* * * * *
 *     *
  *   *
   * *
    *
   * *
  *   *
 *     *
* * * * *
Q37Pattern LogicHard

Print a spiral-ish zigzag pattern across 5 columns and 3 rows, where the star position shifts one column to the right each row, wrapping if needed.

*
  *
    *
Q38NumbersHard

Print a number pyramid using only ODD numbers, where row i contains i consecutive odd numbers continuing from the last row.

1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
Q39DebuggingHard

The following code is supposed to print a right-aligned star pyramid but the spacing is wrong. Find and fix the bug.

rows = 5
for i in range(1, rows + 1):
    spaces = " " * (rows + i)
    stars = "* " * i
    print(spaces + stars)
Q40Pattern LogicHard

Print a "staircase" pattern where each row's stars are offset to the right by 2 spaces instead of 1, for 5 rows, all with the SAME number of stars (3) per row.

* * *
  * * *
    * * *
      * * *
        * * *
Q41Mini-ProjectMini-Project

Build a "Pattern Menu" tool. Ask the user to choose a pattern (pyramid/square/triangle) and a size, then print the corresponding shape using stars.

Q42Mini-ProjectMini-Project

Build a "Name Banner" generator. Ask for a name, and print it centered inside a bordered box that's automatically sized to fit the name plus padding.

Q43Mini-ProjectMini-Project

Build a "Calendar Grid" printer. Ask for a number of days in a month and print them in a 7-column grid (one row per week), right-aligned.

Q44Mini-ProjectMini-Project

Build a "Pascal's Triangle Printer" that asks the user how many rows to generate, then prints a centered Pascal's triangle of that size.

Q45Mini-ProjectMini-Project

Build a "Diamond Customizer". Ask the user for the fill character, size, and whether they want it solid or hollow, then print the matching diamond.

Q46InterviewInterview

Explain the general strategy for solving ANY pattern-printing problem (rows, columns, and the "what goes in this cell" question), then demonstrate it by deriving a centered pyramid of # from scratch, thinking through spaces vs. symbols per row in comments.

Q47InterviewInterview

Given a solid diamond pattern, explain and demonstrate how to convert it into a hollow one by identifying exactly which positions in each row are "border" cells versus "interior" cells.

Q48InterviewInterview

Demonstrate how the same pyramid pattern can be built two different ways: using string multiplication ("* " * i) versus an explicit inner for loop appending characters one at a time. Explain the tradeoff in a comment.

Q49InterviewInterview

A common interview follow-up is "now make it work for an even bigger/smaller size without rewriting the logic." Demonstrate that your pyramid-printing code already generalizes by driving it from a single rows variable read via input(), with no other line needing to change.

Q50CapstoneInterview

Build a "Pattern Showcase" — the most complete demonstration in this module. Ask the user for a size n, then print, in order: a left-aligned pyramid, a centered pyramid, a hollow square, and a Pascal's triangle, each preceded by a labeled header.

Still stuck on something?

Book a free 1-on-1 session and we'll work through it together.

Book a Free Session