CBSE CS and IP

CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

Functions (2 Marks Questions)

  1.  What is a Function? Explain with full programming Example?
  2. Explain the use of “return Keyword” in function? What will happen if we do not write “return”?
  3. What are Keyword (Named) arguments in a function? Explain with full programming example?

  4. What is Default argument in a function? Explain with full programming example?  
  5. Write a program to find the greater of two numbers using function and return the greater number?

  6. What is argument in function? Write the difference between Actual and Formal arguments?

  7. Which definition of function is Valid write the reason:

    • def interest(prin,time,rate=0.10)
    • def interest(prin,time=2,rate)
  8. Write the output of the following code:
    def increment(n):
        n.append([4,3])
        return n
    L=[1,2,3,6]
    M=increment(L)
    print(L,M)

  9. Write definition of a Method AFIND(CITIES) to display all the city names from a list of CITIES, which are starting with alphabet A.
    For example:
    If the list CITIES contains ["AHMEDABAD","CHENNAI","NEW DELHI","AMRITSAR","AGRA"]
    The following should get displayed
    AHEMDABAD
    AMRITSAR
    AGRA


  10. What is the output of the below program?
    
    x = 40
    def func():
        global x
        print('x is', x)
        x = 2
        print('Changed global x to', x)
    func()
    print('Value of x is', x)
    
    a) x is 40              b) x is 40
    Changed global x to 2      Changed global x to 2
    Value of x is 40           Value of x is 2
    
    c) x is 40              d) None of the mentioned
    Changed global x to 40
    Value of x is 40
    

  11. What is the output of the following code?
    l=[]
    def convert(b):
        if(b==0):
            return l
        dig=b%2
        l.append(dig)
        convert(b//2)
    convert(6)
    l.reverse()
    for i in l:
        print(i,end="")
    
    a) 011  b) 110  c) 3  d) Infinite loop
    

  12. Write a method/function ISTOUPCOUNT() in python to read contents from a text file WRITER.TXT, to count and display the occurrence of the word ‘‘IS’’ or ‘‘TO’’ or ‘‘UP’’.
    For example:
    If the content of the file is
    
    IT IS UP TO US TO TAKE CARE OF OUR SURROUNDING. 
    IT IS NOT POSSIBLE ONLY FOR THE GOVERNMENT TO TAKE RESPONSIBILITY
    
    The method/function should display
    Count of IS TO and UP is 6
    

  13. Write down the flow of execution with output (which line of code execute first and after and so on) for the code :
    def power(b,p):
       r=b**p
       return r
    def CalcSquare(a):
       a=power(a,2)
       return a
    #_main_
    n=5
    result=CalSquare(n)
    print(result)
    

  14. What is the scope? What is the scope resolving rules of Python? Explain each with program and output.

  15. Rewrite the following Python code after removing all syntax error(s). Underline the correction done.
    def main( ):
     r = input("Enter any radius : ")
     A -pi * maths.pow(r,2)
     Print("Area = "+a)
      Main()
    

  16. Explain the join() and replace() built-in function of python using Examples with output.

  17. Find the Output of the following Code:
    def MIXITNOW(S):
        Size=len(S)
        for I in range(0,Size-1,2):
            WS=S[I]
            S[I]=S[I+1]
            S[I+1]=WS
        for I in range(1,Size,2):
            if(S[I]>='M' and S[I]<='U'):
                S[I]='@'
    
    Word=list('CRACKAJACK');
    MIXITNOW(Word);
    print(Word)
    

  18. Write the difference between local and non-local variables. Explain using Example with Output.
  19. Write a function that takes a positive integer and returns the one’s position digit of that integer.

No comments:

Post a Comment