Sunday 13 November 2016

Print number pyramid in python

Output should be:

Enter the number of rows:5
1  
1  2  
1  2  3  
1  2  3  4  
1  2  3  4  5  


Code: 

row = int(raw_input("Enter the number of rows:"))  # taking input
for i in range (1,row+1):                                             # iterating from 1 to row+1 
    for j in range(i):                                                      # iterating from 0 to i
        print "%d " % (j + 1),                                         # printing value of j in each loop
    print "\n", 

No comments:

Post a Comment