Page 158 - Information_Practice_Fliipbook_Class11
P. 158

Program 6.10 To print multiplication tables

          01 upperLimit = int(input('Enter the upper limit: '))
          02
          03 print('Multiplication Tables for ', 1, 'to', upperLimit)
          04
          05 for i in range(1, 11):
          06     for col in range(1, upperLimit+1):
          07         print('{0:3}'.format(i*col), end=' ')
          08     print()


          C T  04     1.  Consider the code given below:

                         for num in range(10,30,3):
                             print(num-1)
                         Identify the following components of the given loop:
                         a.  Control variable
                         b.  Initial value of control variable
                         c.  Final value of control variable
                         d.  Step value
                         e.  Body of loop
                      2.  Is the following code elegant? If not, rewrite it to make it more elegant:
                         num = 10
                         while(num<30):
                             print(num-1, end = ' ')
                             num = num+3





        6.7 Printing Patterns

        In this section, we will learn to display some nice patterns. We begin with a right triangle of asterisks.

        6.7.1 Right Triangle

        A right triangle has one symbol in the first row, two in the second row, three in the third row, and so on. Let us write a
        program to print such a triangle. The program will only require two inputs, the number of rows (say, nRows) and the
        symbol (say, symbol) to be used in the pattern (see Program 6.11).

         Program 6.11 To display the right triangular pattern of a symbol
          01 '''
          02 Objective: To display the right triangular pattern of a symbol
          03 Inputs:
          04     nRows : number of rows
          05     symbol: symbol to be printed
          06 Output: Pattern
          07 '''
          08 nRows = int(input('Enter the number of rows: '))
          09 symbol = input('Enter Symbol: ')
          10 for i in range(1, nRows + 1):
          11     for j in range(1, i + 1):
          12         print(symbol, end = '')
          13     print()



          144  Touchpad Informatics Practices-XI
   153   154   155   156   157   158   159   160   161   162   163