Logic Building
def print_numbers(n, current=1):
# Base case
if current > n:
return
# Print current number
print(current, end="")
# Recurse
print_numbers(n, current + 1)
def print_pattern(n, row=1):
# Base case
if row > n:
return
# Print row
print_numbers(row)
print()
# Recurse
print_pattern(n, row + 1)
# Test
n = int(input("Enter rows: "))
print_pattern(n)Output
Enter rows: 4 1 12 123 1234
Use helper to print numbers, main function for rows.
Key Concepts:
- Helper prints 1 to n
- Main function prints rows
- Recursive structure