Page 258 - Computer Science Class 11 With Functions
P. 258

17         nSpaces = nSpaces - 1
          18         nSymbols = nSymbols + 2
         >>> isoscelesTriangle(6,"*")
        Sample Output:
                   *
                  ***
                 *****
                *******
               *********
              ***********
        Fig 10.7 : Isosceles Triangle

        10.7.1 Power Drum

        Having learnt, how to display an inverted isosceles triangle (program 10.13) and an isosceles triangle (Program 10.14),
        to display a power drum we just need to invoke these functions. For example, to display a power drum of asterisks
        comprising 12 rows, we need to display an inverted isosceles triangle, followed by an isosceles triangle, each comprising
        six rows. Note that the number of rows in a power drum is always even.

         Program 10.15 Write a function powerDrum(nRows,symbol) to display the power drum pattern of a symbol.

          01 def powerDrum(nRows, symbol):
          02     '''
          03     Objective: To display an power drum pattern
          04     Inputs:
          05       nRows : number of rows
          06       symbol: symbol to be used in the pattern
          07     Return value: None
          08     '''
          09     #Approach: Ensure nRows is even
          10     #Invoke functions invertedIsoTriangle,isoscelesTriangle
          11     assert nRows%2==0, 'A power drum must have even no of rows'
          12     invertedIsoTriangle(nRows//2, symbol)
          13     isoscelesTriangle(nRows//2, symbol)
         >>> powerDrum(12,'*')

        Sample Output:
              ***********
               *********
                *******
                 *****
                  ***
                   *
                   *
                  ***
                 *****
                *******
               *********
              ***********
        Fig 10.8: Power Drum
        10.7.2 Diamond

        To  display  a  diamond,  it  would  be  tempting  to  invoke  the  functions  isoscelesTriangle() and
        invertedIsoTriangle().  We  first  display  the  isosceles  triangle  and  then  the  inverted  isosceles  triangle
        (see Fig 10.9).




         256   Touchpad Computer Science-XI
   253   254   255   256   257   258   259   260   261   262   263