Monday, July 1, 2019

Class Test 3 - CS 12 - 28/6/2019


Class Test 3 - CS 12
Q1. What is the advantage of having function in a program?
Ans1. The advantages are:
  1. With function we can have code reuse
  2. The debugging process becomes easy
  3. Implementation of new features and removing existing features becomes easy
  4. Reduction of duplicate code
  5. Decomposing complex problems into simple pieces
  6. Information hiding
Q2. Differentiate between Arguments and Parameters with code(python).
Ans:- Parameter:- The variables that are used in the function header during function declaration are    called as parameters. Eg
               def  add(a, b, c): # Here a,b,c are the parameters
                              return a+b+c
               Types of parameter are:
  1. Positional -         add(a,b)
  2. Default -              add(a=10, b=5)  
  3. Variable length - add( *a)
          Arguments:- The actual values that are passed to the function  during function call. Eg
               add(10,45,23)     #  Here 10, 45, 23 are the Arguments (Positional)

Share: