⚡ TL;DR
Print the repeated letter rows pattern in Python. Complete working code, expected output, algorithm explanation, and practice variations for beginners learning loops.
The Repeated Letter Rows pattern is a classic loop exercise. Here’s the complete implementation in Python with working code and output.
Pattern to Print
A
BB
CCC
DDDD
EEEEEImplementation
def repeated_letter(n):
for i in range(1, n + 1):
print(chr(64 + i) * i)
repeated_letter(5)Output
A
BB
CCC
DDDD
EEEEEHow It Works
Row i prints the i-th letter of the alphabet repeated i times.
Practice Variations
- Try printing the pattern with a different character (e.g.,
#or+) - Modify the code to accept the pattern size as user input
- Combine this pattern with its inverse to create a more complex shape
Complexity
- Time: O(n²) — the grid or line count grows quadratically
- Space: O(1) — only loop counters are needed
Related Patterns
- Repeated Letter Rows in Dart
- Repeated Letter Rows in Go
- Repeated Letter Rows in Swift
- Alphabet Rectangle in Python
- Hollow Alphabet Square in Python
- Letter X Shape in Python
FAQ
How do you print the Repeated Letter Rows pattern in Python?
Use nested loops: the outer loop walks through the rows while the inner loop prints the characters or values for each row. The complete Python implementation with expected output is shown in the sections above.
What is the time complexity of the Repeated Letter Rows pattern in Python?
The time complexity is O(n²) and the space complexity is O(1), since the pattern is built with a fixed number of loop counters and printed row by row.
Happy coding!
