Page 629 - ComputerScience_Class_11
P. 629

37. Write a program to print Floyd’s triangle.
                     Program 37.py
                  File  Edit  Format   Run   Options   Window     Help


                  rows = int(input("Enter the number of rows: "))
                  num = 1
                  for i in range(1, rows + 1):
                      for j in range(1, i + 1):
                          print(num, end=" ")
                          num += 1
                      print()

                 The output of the preceding program is as follows:

                     Output

                  Enter the number of rows: 5
                  1
                  2 3
                  4 5 6
                  7 8 9 10
                  11 12 13 14 15


                 38. Write a program to print the multiplication tables within a range of entered numbers.
                     Program 38.py
                  File  Edit  Format   Run   Options   Window     Help

                  start = int(input("Enter the starting number: "))
                  end = int(input("Enter the ending number: "))
                  for i in range(start, end + 1):
                      print("Multiplication Table for ",i,":")
                      for j in range(1, 11):
                          print(i,"x",j,"=",i * j)
                      print()

                 The output of the preceding program is as follows:

                     Output

                  Enter the starting number: 9
                  Enter the ending number: 10
                  Multiplication Table for 9:
                  9 x 1 = 9
                  9 x 2 = 18
                  9 x 3 = 27
                  9 x 4 = 36
                  9 x 5 = 45
                  9 x 6 = 54
                  9 x 7 = 63
                  9 x 8 = 72
                  9 x 9 = 81
                  9 x 10 = 90







                                                                                                Internal Assessment  627
   624   625   626   627   628   629   630   631   632   633   634