Python Pyramid Pattern with Numbers
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This Python code prints an upward number pyramid pattern. The variable n controls the height of the pyramid.
It uses nested loops to print spaces and numbers for each row. The outer loop iterates over each row, the first inner loop prints spaces (n-i-1), and the second inner loop prints numbers from 1 to (2*i+1).
To customize the height, change the value of n. The output for n=5 is:
1 123 12345 1234567 123456789
This pattern is a classic exercise for practicing loops in Python.