important question of working with function class 12

important questions of
working with function

working with function

Q 1. what data type is object below?

           L=1,23,’hello’,1
sol. tuple

Q 2.which python library need to be imported to use following function?

           (1)float()             (2)randint()
sol.  (1)built-in (no module)
          (2) random module

Q 3. which of the following is valid arithmetic operator in python?

    (1)//         (2)?      (3)<         (4)and
sol. (1)//

Q 4. would expression 3**1**3 and 3*1**3 evaluate to same result(true/false)?

sol.  true

Q 5. which of the following expressions results in an error?

   (1)float(’12’)     (2)int(’12’)    (3)float(‘12.5’)     (4)int(‘12.5’)
sol. (d) int(‘12.5’)

Q 6. from the program code given below,identify the parts mentioned                           below.

        def  processnumber(x):
                x=72
                return x=3
        y=54
        res=processnumber(y)
identify these parts: function header,function call,argument,parameter,function body,main program.
sol.  function header: def  processnumber(x):
        function call:  processnumber(y)
        argument:    y
        parameter:   x
        function body:   x=72
                                     return x=3
        main program:    y=54
                                       res=processnumber(y)

Q 6. find output of the code.

  def   power(b,p):
                 y=b**p
                  return y
         def   calcsquare(x):
                  a=power(x,2)
                   return a
         n=5
         result=calcsquare(n) + power(3,3)
         print(result)
sol.  output
        1-5-9-10-5-6-1-2-3-6-7-10-1-2-3-10-11

Q 7. what is the difference between the formal parameter and actual parameter.

sol. actual parameter:- is a parameter,which is used in function call statement to send the value from the calling function to the called function. it is known as argument.
formal parameter:- is a parameter,which is used in function header of the called function to receive the value from the actual parameter.it is also known as parameter.

Q 8. what is the default return value for a function that does not return any value explicitly.

      (a)none    (b)int       (c)double     (d) null
sol. (a)none

Q 9. which names are local,which are global and which are built-in in the following code fragment.

           invaders=”big names”
          pos=200
          level=1
         def   play():
                  max_level=level + 10
                  print(len(invaders)==0)
                  returnmax_level
         res=play()
         print(res)
sol.  global names:-   invaders,pos,level,res
        local names:-max_level
       built_in:-  len

Q 10. predict the output.

 def  func(message,num+1):
                print(message*num)
        func(‘python’)
        func(‘easy’,3)
sol.  output
         python
         easyeasyeasy

Q 11. find output of the code.

           a=1
           def  f():
                   a=10
           print(a)
sol.  output
        1

Q 12. find output of the code.

            def check(n1=1,n2=2):
                   n1=n1+n2
                   n2+=1
                  print(n1,n2)
          check()
          check(2,1)
           check(3)
sol.  output
        3  3
        3   2
       5   3

Q 13. is return statement optional? compare and comment on the following two return statement.
return
return val

sol. the return statement is optional only when the function is void or we can say that when the function does not return a value.a function that return a value,must have at-least one one return from given two return statements,statement.
return
is not returning any value,rather it returns the control to caller along with empty value none.and the statement.
return val
is returning the control to caller along with the value contained in variable val.

Q 14. write function that takes a positive integer and returns the one’s position digit of the integer.

sol. def  getones(num):
               #return the ones digit of the intiger num
               onesdigit=num%10
               return onesdigit

Q 15.what is the possible outcomes executed from the following code?also specify the maximum and minimum values that can be assigned to variable number.

      string=”CBSEONLINE”
      number=random.randint(0,3)
     n=9
    while string[n] != ‘L’ :
               print(string[n]+string[number]+’#’,end=’ ‘)
               number=number+1
               n=n-1
 (1)ES#NE#IO#        (2)LE#NO#ON#      (3)NS#IE#LO#       (4)EC#NB#IS#
sol. part (4) can be one of possible outcomes.
        maximum value 3,minimum value 0.

working with function notes