Page 81 - Code & Click - 8
P. 81

D.  Answer the following questions.

                1.  What is a function? How is it useful in programming?
                2.  Describe the components of a user-defined function in Python.

                3.  Explain any three functions used to work with strings in Python.
                                                                                                  Computational Skills
              Mind Stretching
             1. Write the code segment to perform the following tasks in Python.

                 (a)  Display the last character in a string variable named “Name”.
                 (b)  Add an element “Program” to a list named “Objects”.
                 (c)  Define a function named “Volume” that takes three arguments – l, b, and h, and returns the
                     volume of the cuboid.
                 (d)  Display all odd numbers from 5 to 30.
             2. Identify and underline the errors in the code given below. Also, write the correct code.

                # Program to create a function that accepts two numbers and returns their sum.
                def sum_num(a, b)

                sum = a + b
                return sum
                sum_num(20, 45)
                display(“Sum of numbers =”, sum)

             3. Write the output of the following code segments in Python:
                list_num_1 = [2, 3, 5, 7, 11, 13, 17, 19]
                print(list_num_1)
                list_num_1.pop(4)
                print(llist_num_1[5])
                list_num_1.append(23)
                print(list_num_1[-1])


                                                                                                  Computational Skills
             Lab Work

             Write the following in Python:
               (a)  Program to create a function to accept length and breadth of a rectangle and display its area and
                    perimeter.
               (b)  Program to create a function that accepts three numbers from the user and displays the largest
                    number among the three.
               (c)  Program to create a list that stores all multiples of 11 between 1 and 100 and display the list.














                                                                                                                 79
   76   77   78   79   80   81   82   83   84   85   86