Friday, July 6, 2012

Create a Pyramid in Python

open a python script editor and just paste the following code in your new python(.py or .pyw) file -

def createPyramid ():
    minVal = 1
    maxVal = 35
    index = maxVal/2
    for r in xrange(minVal,maxVal,2):
        print " " * index + "*" * r
        index = index - 1
       
createPyramid()

output is-

1 comment:

  1. May you please explain each segment of your code, so that new programming students as myself can get the definite logic in your code?

    ReplyDelete