Time remaining:

Making an hour glass?


label Programming
account_circle Unassigned
schedule 0 Hours
account_balance_wallet $5

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: 

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

Nov 21st, 2017

# 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

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Nov 21st, 2017
...
Nov 21st, 2017
Nov 22nd, 2017
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