Page 232 - Computer Science V2.0 Class 11
P. 232

<class 'float'>
                    >>>  pow(2,3)
                    8
                    >>>  math.pow(2,3)
                    8.0
                 5.  Using an example show how a function in Python can return multiple values.
               Ans.  A function in python can return multiple values in the form of tuple.
                    import math
                    def sphereVolumeSurfaceArea(radius):
                        volume = (4/3) * math.pi * radius**3
                        surfaceArea = 4 * math.pi * radius**2
                        return volume, surfaceArea

                    radius = float(input("Enter the radius of the sphere: "))
                    volume, surfaceArea = sphereVolumeSurfaceArea(radius)

                    print(f"Volume of the sphere: {volume:.2f}")
                    print(f"Surface area of the sphere: {surfaceArea:.2f}")
                 6.  Differentiate between following with the help of an example:
                    a. Argument and Parameter
                    b. Global and Local variable
               Ans.  a. Argument: Input values passed during the call to a function (by writing them inside the parenthesis) are called Arguments.
                       Parameter: Variables that receive the values during a call to the function are called parameters. They are mentioned inside the
                      parenthesis in the function header is called parameter.
                       An argument is a value passed to the function during the function call which is received in corresponding parameter defined in
                      function header.
                      def areaCircle(radius):    #radius is the parameter

                          """
                          Objective: To compute the area of the circle
                          Input Parameter:
                          radius- numeric value denoting radius of circle
                          Return value: area of circle
                          """
                          area = 3.14 * radius ** 2
                          return area

                      radius = 5
                      print('radius of circle = ', radius)
                      area = areaCircle(radius) #radius is the argument
                      print('area of circle = ', round(area,2))
                      print('value of pi = ', pi)
                    b.  A variable that has global scope is known as a global variable and a variable that has a local scope is known as a local variable.
                       Global Variable : In Python, a variable that is defined outside a function is known as a global variable. It can be accessed in any
                      functions defined onwards. Any change made to the global variable will impact all the functions in the program where that variable
                      can be accessed. We can modify a global variable inside any function by using the keyword global.
                       Local Variable : A variable that is defined inside a function is known as a local variable. It can be accessed only in the function where
                      it is defined. It exists only till the function executes.
                      Example:
                      from math import sqrt


               218   Touchpad Computer Science (Ver. 2.0)-XI
   227   228   229   230   231   232   233   234   235   236   237