Attribute of while loop


#1

def pyramid(no):
    x=1
    while (x<=no):
        for i in range(1,x+1):
            print i,
        x=x+1
            
            


pyramid(4)

I wanted to create a pyramid of n numbers.
While loop should have given output in new line each time, but the output is still in same line
please help


#2

you could use "\n" to force a new line

How should your pyramid look, like this:

#
##
###
####

o:

  #
 # #    
# # #

#3

the first one was what i was thinking about,


#4

a simple new line:

def pyramid(no):
    x=1
    while (x<=no):
        for i in range(1,x+1):
            print i,
        print "\n"
        x=x+1
            


pyramid(4)

and you have your result


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.