Python Practice › Loop Programs › Program 41
Letter T pattern
Write a Python program to print the letter ‘T’ with stars: two full rows of 9 stars and a 3-star stem in the middle.
Output
* * * * * * * * *
* * * * * * * * *
* * *
* * *
* * *
* * *
* * * Approach
- Print the top bar twice, then the stem rows padded with spaces to centre them.
Solution
width, stem, height = 9, 3, 5for _ in range(2): print("* " * width)pad = (width - stem) // 2for _ in range(height): print(" " * pad + "* " * stem)Output
* * * * * * * * *
* * * * * * * * *
* * *
* * *
* * *
* * *
* * * Line by line
Line 3
"* " * 9 repeats the star-space pair 9 times.
Line 4
The stem starts 3 star-widths in, so it sits in the centre.
Learn the concept
New to this topic? Read the lesson, then come back.