Search code examples
pythontriangle

How to print pattern where each subsequent column is squared?


Here is the pattern I am trying to print:

1
2 4
3 9 27
4 16 64 256
5 25 125 625 3125

Here is what I have so far, and I am stuck at this point.

for rows in range(1,5+1):
    for columns in range(rows):
        columns= (rows)**rows
        print(columns , end=' ')
    print('')

Solution

  • Try this

    for rows in range(1,5+1):
    for columns in range(1,rows+1):
        columns= (rows)**columns
        print(columns , end=' ')
    print('')
    

    You will need to take it as rows raised to columns. Output:

    1 
    2 4 
    3 9 27 
    4 16 64 256 
    5 25 125 625 3125