Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 141 - 2609_Logicode
P. 141

    Output
                      [1, 3, 4, 5, 6, 7]

                     Program 17: To delete the whole list

                         Program17.py
                      File  Edit  Format   Run    Options   Window    Help

                      a=[1,2,3,4,5,6,7]
                      del a

                     The whole list will be deleted..

                          Tick ( ) if you know this.
                          ▶    A consecutive sequence of characters that are enclosed or surrounded by a single (‘ ’)
                            or double (“ ”) quotes is known as a string.
                          ▶  A list is a type of container that is used to store a list of values of any type.

                               SOME MORE PROGRAMS

                     Program 18: To calculate the area of different shapes

                         Program18.py
                      File  Edit  Format   Run    Options   Window    Help

                      def calculate_area(name):
                          name = name.lower()
                          if(name == 'rectangle'):
                              l = float(input('Enter the length of the rectangle: '))
                              b = float (input('Enter the breadth of the rectangle: '))
                              rect_area = 1 * b
                              print('The area of the rectangle is: ', rect_area)
                          elif(name == 'square'):
                              s = float(input('Enter the side of the square: '))
                              sqr_area = s * s
                              print('The area of the square is:', sqr_area)
                          elif (name == 'circle'):
                              pi = 3.14
                              r = float(input('Enter the radius of the circle: '))
                              circle_area = pi * r**2
                              print('The area of the circle is: ', circle_area)
                          else:
                              print('sorry! This shape is not available')
                      print('Calculate Area for: Rectangle, Square, or Circle')
                      shape_name = input('Enter the name of the shape whose area you want to find: ')
                      calculate_area(shape_name)

                                                                                               String and List in Python  139

| 136 137 138 139 140 141 142 143 144 145 146 |