Python · Python Fundamentals

Pattern Printing: Practice Questions

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

Short on time? Filter by Must Do for the 25 questions that cover this topic on their own.

Q1StarsEasyMust Do

Print a single row of 5 stars using a loop, so the output is *****.

Q2StarsEasy

Print the same row of 5 stars without a loop, using string repetition.

Q3StarsEasyMust Do

Print a 5x5 square of stars using nested loops.

Q4StarsEasy

Print the same 5x5 square using only one loop and string repetition.

Q5StarsEasyMust Do

Print a right-angled triangle that grows from 1 star to 5 stars.

*
**
***
****
*****
Q6StarsEasy

Print the same growing triangle using nested loops instead of repetition.

Q7StarsEasy

Print a shrinking right-angled triangle, from 5 stars down to 1.

*****
****
***
**
*
Q8NumbersEasy

Print the numbers 1 to 5 across a single line, separated by spaces.

Q9NumbersEasy

Print a 5x5 square where every row reads 1 2 3 4 5.

Q10NumbersEasy

Print a 5x5 square where every row repeats its own row number.

1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
Q11NumbersEasyMust Do

Print a growing number triangle where each row counts up from 1.

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Q12NumbersEasy

Print a growing triangle where each row repeats its own row number.

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Q13NumbersEasy

Print a shrinking number triangle, starting with 1 2 3 4 5 and losing the last number each row.

Q14AlphabetsEasyMust Do

Print the letters A to E across one line, using chr() and ord().

Q15AlphabetsEasy

Print a growing letter triangle where every row starts again at A.

A
A B
A B C
A B C D
A B C D E
Q16AlphabetsEasy

Print a growing triangle where each row repeats its own letter.

A
B B
C C C
D D D D
E E E E E
Q17SpacingEasyMust Do

Print a right-aligned triangle by putting spaces before the stars.

    *
   **
  ***
 ****
*****
Q18SpacingEasy

Print a right-aligned shrinking triangle.

*****
 ****
  ***
   **
    *
Q19RectangleEasyMust Do

Ask the user for a width and a height, then print a solid rectangle of stars that size.

Q20NumbersEasy

Print a triangle where each row shows the row number at the front, then that many stars.

1 *
2 **
3 ***
4 ****
5 *****
Q21Floyd's TriangleEasyMust Do

Print a triangle where the numbers keep counting up continuously across rows, rather than restarting.

1
2 3
4 5 6
7 8 9 10
Q22AlphabetsEasy

Print a letter triangle where the letters run continuously across rows: A, then B C, then D E F.

Q23NumbersEasy

Print a triangle of even numbers, where each row counts up in twos.

2
2 4
2 4 6
2 4 6 8
Q24NumbersEasy

Print a triangle of odd numbers, where each row counts up in odds starting from 1.

Q25StarsEasy

Print a row of 10 stars with a space between each, using end rather than string repetition.

Q26PyramidMediumMust Do

Print a centred pyramid of stars with 5 rows.

    *
   ***
  *****
 *******
*********
Q27Inverted PyramidMediumMust Do

Print an inverted pyramid of stars with 5 rows.

*********
 *******
  *****
   ***
    *
Q28PyramidMedium

Print a number pyramid where each row counts up to the row number and the rows are centred.

    1
   1 2
  1 2 3
 1 2 3 4
1 2 3 4 5
Q29Inverted PyramidMedium

Print an inverted number pyramid.

1 2 3 4 5
 1 2 3 4
  1 2 3
   1 2
    1
Q30PyramidMedium

Print a centred alphabet pyramid where each row starts at A.

    A
   A B
  A B C
 A B C D
A B C D E
Q31Hollow PatternsMediumMust Do

Print a hollow 5x5 square — stars only on the border.

*****
*   *
*   *
*   *
*****
Q32Hollow PatternsMedium

Print a hollow right-angled triangle with 5 rows.

*
**
* *
*  *
*****
Q33Hollow PatternsMedium

Print a hollow pyramid with 5 rows.

    *
   * *
  *   *
 *     *
*********
Q34DiamondMediumMust Do

Print a solid diamond of stars with 5 rows in the upper half.

    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
Q35DiamondMedium

Print a hollow diamond with 5 rows in the upper half.

Q36NumbersMedium

Print a centred number palindrome pyramid.

    1
   121
  12321
 1234321
123454321
Q37Binary PatternMedium

Print a triangle of alternating 1s and 0s, where each row starts with 1.

1
10
101
1010
10101
Q38MirroredMedium

Print a mirrored right triangle: right-aligned stars with no leading gaps visible.

    *
   **
  ***
 ****
*****
Q39ButterflyMedium

Print a butterfly pattern with 4 rows per wing.

*      *
**    **
***  ***
********
********
***  ***
**    **
*      *
Q40X PatternMedium

Print an X (cross) pattern in a 5x5 grid.

*   *
 * *
  *
 * *
*   *
Q41Plus PatternMedium

Print a plus sign in a 5x5 grid.

  *
  *
*****
  *
  *
Q42Half DiamondMedium

Print a half diamond (left-aligned) with 4 rows in the upper half.

*
**
***
****
***
**
*
Q43HourglassMedium

Print an hourglass (sandglass) of stars with 5 rows in the upper half.

*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********
Q44CheckerboardMediumMust Do

Print an 8x8 checkerboard using # and a space, alternating in both directions.

Q45ZigzagMedium

Print a zigzag wave across 9 columns and 3 rows.

*   *   *
 * * * *
  *   *
Q46Hollow PatternsMedium

Print a hollow inverted pyramid with 5 rows.

Q47StaircaseMedium

Print a staircase of 5 steps, where each step is a block of stars one wider than the last, right-aligned.

Q48Double PatternMedium

Print two right triangles side by side, separated by 4 spaces.

*        *
**      **
***    ***
****  ****
**********
Q49Custom CharacterMediumMust Do

Ask the user for a character and a height, then print a pyramid made of that character.

Q50AlphabetsMedium

Print a centred alphabet pyramid that counts up then back down.

    A
   ABA
  ABCBA
 ABCDCBA
ABCDEDCBA
Q51Pascal's TriangleMediumMust Do

Print Pascal's triangle with 6 rows. Work each value out from the previous one using the combination formula — no lists needed.

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Q52Pascal's TriangleMedium

Print Pascal's triangle with 6 rows, centred so it forms a proper triangle.

Q53GridMediumMust Do

Print a full multiplication grid from 1x1 to 9x9 with aligned columns.

Q54GridMedium

Print a multiplication grid with a header row and column, separated by rules.

Q55Bar ChartMediumMust Do

Ask for 5 values and print a horizontal bar chart, one row per value, using # blocks.

Q56Progress BarMedium

Print a progress bar at 0%, 25%, 50%, 75% and 100%, each 20 characters wide.

Q57Bar ChartMedium

Ask for a rating out of 5 and print it as a star bar padded to 5 characters, plus a numeric label.

Q58NumbersMedium

Print a right-aligned number triangle where each row counts up to the row number.

        1
      1 2
    1 2 3
  1 2 3 4
1 2 3 4 5
Q59DiamondMedium

Print a diamond made of numbers, where each row shows its own row number repeated.

Q60ValidationMediumMust Do

Ask the user for a pyramid height, reject anything below 1 or above 20, and print the pyramid only when the height is sensible.

Q61Custom CharacterMedium

Ask for a word and print a triangle where each row repeats the word that many times.

Q62AlphabetsMedium

Ask for a name and print it as a right-angled triangle, revealing one more letter each row.

A
As
Ash
Asha
Q63AlphabetsMedium

Print an inverted name triangle, losing one letter from the end each row.

Q64GridMedium

Print the printable ASCII codes 65 to 90 as a grid of 6 columns, showing each code and its letter.

Q65CalendarMedium

Print a simple month grid of 30 days, 7 columns wide, with the numbers right-aligned.

Q66Hollow PatternsMedium

Print a hollow rectangle of a width and height the user chooses.

Q67Border BoxMediumMust Do

Ask for a message and print it inside a neat box made of +, - and |.

Q68TriangleMedium

Print a triangle where each row's numbers descend from the row number down to 1.

1
2 1
3 2 1
4 3 2 1
Q69TriangleMedium

Print a triangle showing the squares of the numbers in each row.

1
1 4
1 4 9
1 4 9 16
Q70GridMedium

Print a 5x5 grid showing the sum of each row and column index, so the diagonal pattern is visible.

Q71Hollow PatternsHard

Print a hollow diamond made of numbers, where each edge shows the row number.

Q72ConcentricHard

Print a 7x7 grid of concentric square rings, where each cell shows how far it is from the border.

1111111
1222221
1233321
1234321
1233321
1222221
1111111
Q73SpiralHard

Print a 7x7 square with a border of *, an inner border of spaces, and a solid * core — three concentric layers.

Q74CompoundHard

Print a diamond of stars sitting inside a hollow square, both 9 wide.

Q75Pattern LogicHardMust Do

Explain, with working code, the general formula for a centred pyramid of any height — showing how the space count and star count relate to the row number.

Q76Pattern LogicHard

Show why a diamond needs its second loop to start at rows - 1 rather than rows, by printing both versions.

Q77DebuggingHardMust Do

This should print a pyramid but prints a left-aligned triangle instead. Find and fix the bug.

rows = 5
for row in range(1, rows + 1):
    print(" " * row + "*" * (2 * row - 1))
Q78DebuggingHard

This should print a 3x3 square of stars but prints one star per line. Find and fix the bug.

for row in range(3):
    for col in range(3):
        print("*")
Q79DebuggingHard

This should print 5 rows but prints only 4. Find and fix the bug.

rows = 5
for row in range(1, rows):
    print("*" * row)
Q80DebuggingHard

This hollow square is solid instead of hollow. Find and fix the bug.

size = 5
for row in range(size):
    for col in range(size):
        if row == 0 or row == size - 1 or col == 0 or col == size:
            print("*", end="")
        else:
            print(" ", end="")
    print()
Q81Floyd's TriangleHard

Print Floyd's triangle with 5 rows, right-aligned so the columns line up neatly.

Q82AlphabetsHard

Print an alphabet diamond that counts up to the middle letter and back down.

Q83ButterflyHard

Print a hollow butterfly with 5 rows per wing.

Q84Pattern LogicHard

Print a 5x5 grid where each cell shows row * col, but only where the row and column indexes are both even — spaces elsewhere.

Q85CompoundHardMust Do

Print a pyramid where the border is * and the inside is filled with the row number.

Q86Mini-ProjectMini-ProjectMust Do

Build a Pattern Menu. Offer pyramid, inverted pyramid, diamond and hollow square; ask for a size; then print the chosen pattern.

Q87Mini-ProjectMini-Project

Build a Custom Pyramid Builder. Ask for the height, the character to use, and whether it should be hollow, then print accordingly.

Q88Mini-ProjectMini-Project

Build a Diamond Generator that asks for a size and character and prints a solid diamond, then a hollow one, labelled.

Q89Mini-ProjectMini-Project

Build a Bar Chart Generator. Ask how many bars, then collect a label and a value for each and print a scaled chart with the values shown.

Q90Mini-ProjectMini-Project

Build a Calendar Grid. Ask for the number of days in the month and which weekday it starts on (0 = Monday), then print a proper calendar grid.

Q91Mini-ProjectMini-Project

Build a Chessboard Renderer. Ask for a size and print a board with alternating squares and file/rank labels.

Q92Mini-ProjectMini-ProjectMust Do

Build a Text Framer. Ask for three lines of text and print them inside a box wide enough for the longest line, with everything centred.

Q93Mini-ProjectMini-Project

Build a Pascal's Triangle Generator. Ask for the number of rows and print it centred with aligned columns.

Q94Mini-ProjectMini-Project

Build a Times Table Poster. Ask for a number and print its table from 1 to 12 inside a decorated box.

Q95Mini-ProjectMini-Project

Build a Loading Bar Sequence. Print a 30-wide progress bar at every 10% step, showing the percentage and a filled/empty split.

Q96InterviewInterview

Explain the universal structure behind every pattern in this topic, and demonstrate it by building one pattern step by step.

Q97InterviewInterview

Explain the general rule for making any solid pattern hollow, and demonstrate it on a square and a triangle.

Q98InterviewInterview

Explain how Pascal's triangle can be printed without storing any previous row, and prove the values are correct for 7 rows.

Q99InterviewInterview

Given a pattern you have never seen, describe the method for working out its formula — then apply it to derive and print this one.

1
2 3
4 5 6
7 8 9 10
Q100CapstoneInterviewMust Do

Build a Pattern Gallery — the fullest demonstration of this topic. For a single size of 5, print, each with a heading: a solid pyramid, an inverted pyramid, a diamond, a hollow square, an X, Floyd's triangle and Pascal's triangle.

Still stuck on something?

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

Book a Free Session