#!/usr/bin/python # pyramid.py # # This program will draw a pyramid of asterisks # according to user input. # # Print a blank line print # Ask the user for the number of rows in this pyramid. rows = input("How tall shall we build your pyramid? ") # Print a blank line print # Below this line is a block of code that will draw one row of the pyramid. # We use a for loop because we need to run that code for each row. # range(m+1) creates a list of integers from 1 to (m ) # e.g. range(7+1) = [1, 2, 3, 4, 5, 6,7] for row in range(rows+1): out=" "*(rows-row)+"* "*row # Put the right number of spaces plus the right number of stars # THere is no reason to do loops print out # Print the row out to the output # Notice that we don't need to count the space to the right. # This is a little message to let the user know that we are done. print print "Enjoy your pyramid!" print