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.
Print a single row of 5 stars using a loop, so the output is *****.
Print the same row of 5 stars without a loop, using string repetition.
Print a 5x5 square of stars using nested loops.
Print the same 5x5 square using only one loop and string repetition.
Print a right-angled triangle that grows from 1 star to 5 stars.
*
**
***
****
*****
Print the same growing triangle using nested loops instead of repetition.
Print a shrinking right-angled triangle, from 5 stars down to 1.
*****
****
***
**
*
Print the numbers 1 to 5 across a single line, separated by spaces.
Print a 5x5 square where every row reads 1 2 3 4 5.
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
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
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
Print a shrinking number triangle, starting with 1 2 3 4 5 and losing the last number each row.
Print the letters A to E across one line, using chr() and ord().
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
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
Print a right-aligned triangle by putting spaces before the stars.
*
**
***
****
*****
Print a right-aligned shrinking triangle.
*****
****
***
**
*
Ask the user for a width and a height, then print a solid rectangle of stars that size.
Print a triangle where each row shows the row number at the front, then that many stars.
1 *
2 **
3 ***
4 ****
5 *****
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
Print a letter triangle where the letters run continuously across rows: A, then B C, then D E F.
Print a triangle of even numbers, where each row counts up in twos.
2
2 4
2 4 6
2 4 6 8
Print a triangle of odd numbers, where each row counts up in odds starting from 1.
Print a row of 10 stars with a space between each, using end rather than string repetition.
Print a centred pyramid of stars with 5 rows.
*
***
*****
*******
*********
Print an inverted pyramid of stars with 5 rows.
*********
*******
*****
***
*
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
Print an inverted number pyramid.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
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
Print a hollow 5x5 square — stars only on the border.
*****
* *
* *
* *
*****
Print a hollow right-angled triangle with 5 rows.
*
**
* *
* *
*****
Print a hollow pyramid with 5 rows.
*
* *
* *
* *
*********
Print a solid diamond of stars with 5 rows in the upper half.
*
***
*****
*******
*********
*******
*****
***
*
Print a hollow diamond with 5 rows in the upper half.
Print a centred number palindrome pyramid.
1
121
12321
1234321
123454321
Print a triangle of alternating 1s and 0s, where each row starts with 1.
1
10
101
1010
10101
Print a mirrored right triangle: right-aligned stars with no leading gaps visible.
*
**
***
****
*****
Print a butterfly pattern with 4 rows per wing.
* *
** **
*** ***
********
********
*** ***
** **
* *
Print an X (cross) pattern in a 5x5 grid.
* *
* *
*
* *
* *
Print a plus sign in a 5x5 grid.
*
*
*****
*
*
Print a half diamond (left-aligned) with 4 rows in the upper half.
*
**
***
****
***
**
*
Print an hourglass (sandglass) of stars with 5 rows in the upper half.
*********
*******
*****
***
*
***
*****
*******
*********
Print an 8x8 checkerboard using # and a space, alternating in both directions.
Print a zigzag wave across 9 columns and 3 rows.
* * *
* * * *
* *
Print a hollow inverted pyramid with 5 rows.
Print a staircase of 5 steps, where each step is a block of stars one wider than the last, right-aligned.
Print two right triangles side by side, separated by 4 spaces.
* *
** **
*** ***
**** ****
**********
Ask the user for a character and a height, then print a pyramid made of that character.
Print a centred alphabet pyramid that counts up then back down.
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
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
Print Pascal's triangle with 6 rows, centred so it forms a proper triangle.
Print a full multiplication grid from 1x1 to 9x9 with aligned columns.
Print a multiplication grid with a header row and column, separated by rules.
Ask for 5 values and print a horizontal bar chart, one row per value, using # blocks.
Print a progress bar at 0%, 25%, 50%, 75% and 100%, each 20 characters wide.
Ask for a rating out of 5 and print it as a star bar padded to 5 characters, plus a numeric label.
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
Print a diamond made of numbers, where each row shows its own row number repeated.
Ask the user for a pyramid height, reject anything below 1 or above 20, and print the pyramid only when the height is sensible.
Ask for a word and print a triangle where each row repeats the word that many times.
Ask for a name and print it as a right-angled triangle, revealing one more letter each row.
A
As
Ash
Asha
Print an inverted name triangle, losing one letter from the end each row.
Print the printable ASCII codes 65 to 90 as a grid of 6 columns, showing each code and its letter.
Print a simple month grid of 30 days, 7 columns wide, with the numbers right-aligned.
Print a hollow rectangle of a width and height the user chooses.
Ask for a message and print it inside a neat box made of +, - and |.
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
Print a triangle showing the squares of the numbers in each row.
1
1 4
1 4 9
1 4 9 16
Print a 5x5 grid showing the sum of each row and column index, so the diagonal pattern is visible.
Print a hollow diamond made of numbers, where each edge shows the row number.
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
Print a 7x7 square with a border of *, an inner border of spaces, and a solid * core — three concentric layers.
Print a diamond of stars sitting inside a hollow square, both 9 wide.
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.
Show why a diamond needs its second loop to start at rows - 1 rather than rows, by printing both versions.
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))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("*")This should print 5 rows but prints only 4. Find and fix the bug.
rows = 5
for row in range(1, rows):
print("*" * row)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()Print Floyd's triangle with 5 rows, right-aligned so the columns line up neatly.
Print an alphabet diamond that counts up to the middle letter and back down.
Print a hollow butterfly with 5 rows per wing.
Print a 5x5 grid where each cell shows row * col, but only where the row and column indexes are both even — spaces elsewhere.
Print a pyramid where the border is * and the inside is filled with the row number.
Build a Pattern Menu. Offer pyramid, inverted pyramid, diamond and hollow square; ask for a size; then print the chosen pattern.
Build a Custom Pyramid Builder. Ask for the height, the character to use, and whether it should be hollow, then print accordingly.
Build a Diamond Generator that asks for a size and character and prints a solid diamond, then a hollow one, labelled.
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.
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.
Build a Chessboard Renderer. Ask for a size and print a board with alternating squares and file/rank labels.
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.
Build a Pascal's Triangle Generator. Ask for the number of rows and print it centred with aligned columns.
Build a Times Table Poster. Ask for a number and print its table from 1 to 12 inside a decorated box.
Build a Loading Bar Sequence. Print a 30-wide progress bar at every 10% step, showing the percentage and a filled/empty split.
Explain the universal structure behind every pattern in this topic, and demonstrate it by building one pattern step by step.
Explain the general rule for making any solid pattern hollow, and demonstrate it on a square and a triangle.
Explain how Pascal's triangle can be printed without storing any previous row, and prove the values are correct for 7 rows.
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
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