Time remaining:
Making an hour glass?

Programming
Tutor: None Selected Time limit: 0 Hours

I have to write a program that makes an hour glass when the user enters a number of rows.   I can only calculate stars and spaces using total number of rows and row number.  if the user enters five output should look like this: 

*****
 ***
  *
 ***
*****

Mar 14th, 2015

# Written in Python 2.7

import sys, os

def PrintRow(nPad, nStarCount):

    sLine = ''

   

    for iPad1 in range(nPad):

        sLine += ' '

       

    for iStar in range(nStarCount):

        sLine += '*'

       

    for iPad2 in range(nPad):

        sLine += ' '

       

    print sLine

#end def

   

# begin main    

nArgCount = len(sys.argv)

if (nArgCount != 2):

    print 'Usage: %s <an odd integer number>' % sys.argv[0]

    sys.exit(-1)

   

nLen = int(sys.argv[1])

bIsOdd = ((nLen % 2) == 1)

if (not bIsOdd):

    print 'The input must be an odd integer. You enetered "%d"' % nLen

    sys.exit(-1)

   

nStarCount = nLen

while (nStarCount > 0):

    nPad = (nLen - nStarCount) / 2

    PrintRow(nPad, nStarCount)

    nStarCount -= 2    

nStarCount = 3    

while (nStarCount <= nLen):

    nPad = (nLen - nStarCount) / 2

    PrintRow(nPad, nStarCount)

    nStarCount += 2    


Mar 15th, 2015

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Mar 14th, 2015
...
Mar 14th, 2015
Dec 6th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer