Class 11 Computer Science Chapter 7 Question Bank CBSE Board Pattern

Section A — MCQs (10 questions, 1 mark each)

1. Which of the following is NOT an advantage of using functions in a program?
(a) Increases readability of the program
(b) Reduces code length
(c) Increases reusability
(d) Increases the number of lines in the program

2. A function definition in Python begins with the keyword:
(a) function
(b) def
(c) define
(d) func

3. In the function header def mixedFraction(num, deno = 1):, the parameter deno is an example of:
(a) positional parameter
(b) default parameter
(c) local variable
(d) global variable

4. Which of the following statements is correct regarding default parameters in Python functions?
(a) Default parameters must be the first parameters in the function header.
(b) Default parameters must be the trailing parameters in the function header.
(c) Any parameter can have a default value irrespective of its position.
(d) Default parameters cannot be used with user-defined functions.

5. Assertion (A): A function must be defined before it is called in a Python program.
Reason (R): The Python interpreter executes statements from top to bottom, and a function call transfers control to the function definition.
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.

6. A variable defined inside a function is called a:
(a) global variable
(b) local variable
(c) built-in variable
(d) module variable

7. Which of the following functions is used to find the identity of an object in Python?
(a) id()
(b) type()
(c) len()
(d) range()

8. Assertion (A): Multiple values can be returned from a function using a tuple.
Reason (R): The return statement can return only one value at a time.
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.

9. The statement used to import only specific functions from a module is:
(a) import modulename
(b) from modulename import functionname
(c) import functionname from modulename
(d) include modulename

10. Which of the following is a built-in module in Python?
(a) math
(b) tent
(c) canvas
(d) calc

Section B — Very Short Answer (6 questions, 2 marks each)

1. Define the term 'modular programming' as described in the chapter.

2. Differentiate between a parameter and an argument with reference to user-defined functions.

3. What is the difference between a void function and a function that returns a value?

4. Write the output of the following code fragment and state why the output is generated:
python def helloPython(): print("I love Programming") helloPython()

5. What is the role of the return statement in a user-defined function?

6. Differentiate between a built-in function and a user-defined function.

Section C — Short Answer (5 questions, 3 marks each)

1. Identify the error in the following code and rewrite the corrected code:
python def create(text, freq): for i in range(1, freq): print(text) create(5)

2. Write the output of the following code and explain why the id values change or remain the same:
python def incrValue(num): print("id before increment =", id(num)) num = num + 5 print("id after increment =", id(num)) number = 8 incrValue(number)

3. What will be the output of the following code? Explain briefly.
python def sumSquares(n): sum = 0 for i in range(1, n+1): sum = sum + i print("The sum of first", n, "natural numbers is:", sum) num = 5 sumSquares(num)

4. Identify the error in the following code and give the corrected version:
python def calcInterest(principal = 1000, rate, time = 5): interest = principal * rate * time / 100 print(interest) calcInterest(5000, 0.05)

5. Write the output of the following code fragment:
python def fullname(first, last): fullname = first + " " + last print("Hello", fullname) first = "Gyan" last = "Vardhan" fullname(first, last)

Section D — Long Answer (3 questions, 5 marks each)

1. Write a complete Python program using a user-defined function calcFact(num) that accepts a positive integer as argument and displays its factorial. The program should accept the number from the user and call the function.

2. Explain the flow of execution in a Python program that contains user-defined functions. Illustrate your answer with a dry-run using a trace table for the following code:
python def addnum(a, b): return a + b x = 5 y = 7 result = addnum(x, y) print(result)

3. Write a complete Python program that creates a user-defined module named basic_math containing four functions: addnum(x,y), subnum(x,y), multnum(x,y) and divnum(x,y). Also include a docstring describing the module. Demonstrate importing and using the functions.

Section E — Case/Source-Based (2 questions, 4 marks each)

Case 1: A company wants to calculate the payable amount for tents using modular programming. The program accepts height, radius and slant height, calculates canvas area using two separate functions for cylindrical and conical parts, computes total cost and finally adds 18% tax using another function.

Sub-questions:

(a) Identify the three user-defined functions used in the modular approach.
(b) What is the advantage of using separate functions for cylindrical and conical areas?
(c) Write the function header and body for the function that computes the payable amount after tax.
(d) If the same tax rate is to be used in another program, how can the function be reused?

Case 2: A student is creating a program to simulate a traffic light using two user-defined functions trafficLight() and light(colour). The program accepts a colour and displays appropriate messages.

Sub-questions:

(a) What value does the function light("RED") return?
(b) Which function calls the other function and how?
(c) Write the complete code for the function light(colour).
(d) Why is it important to define functions before calling them in this program?

Answer Key Attempt all questions first,
then tap to reveal

Section A

  1. (d)
  2. (b)
  3. (b)
  4. (b)
  5. (a)
  6. (b)
  7. (a)
  8. (c)
  9. (b)
  10. (a)

Section B

  1. Modular programming is the process of dividing a computer program into separate independent blocks of code or sub-problems with different names and specific functionalities.
  2. An argument is the value passed during function call; a parameter is the variable in the function header that receives the argument.
  3. A void function does not return any value (uses print inside); a function returning value uses the return statement to send value(s) back to the caller.
  4. Output: I love Programming — because the function is called after its definition and the print statement inside the function is executed.
  5. The return statement transfers control back to the calling function and sends value(s) or None to the caller.
  6. Built-in functions are ready-made functions available in Python interpreter (e.g., input(), print()); user-defined functions are written by the programmer using def.

Section C

  1. Error: create(5) passes only one argument but function expects two. Corrected code:
    python def create(text, freq): for i in range(1, freq): print(text) create("Hello", 5)
  2. Output shows same id before increment and different id after increment because num = num + 5 creates a new object.
  3. Output: The sum of first 5 natural numbers is: 15 — because the loop adds numbers from 1 to 5.
  4. Error: default parameter principal appears before non-default parameter rate. Corrected:
    python def calcInterest(rate, principal=1000, time=5): interest = principal * rate * time / 100 print(interest)
  5. Output: Hello Gyan Vardhan — because the two strings are concatenated with a space inside the function.

Section D

  1. Complete program:
    ```python def calcFact(num): fact = 1 for i in range(num, 0, -1): fact = fact * i print("Factorial of", num, "is", fact)

num = int(input("Enter the number: ")) calcFact(num) ``` 2. Flow of execution: statements are executed top to bottom. When a function call is encountered, control jumps to the function definition, executes it, then returns to the point after the call. Trace table:
| Line | x | y | result |
|------|---|---|--------|
| 4 | 5 | | |
| 5 | 5 | 7 | |
| 6 | 5 | 7 | 12 |
| 7 | 5 | 7 | 12 |

  1. Program creates basic_math.py with docstring and four functions as described in Program 7-16 of the chapter.

Section E

Case 1

(a) cyl(h,r), con(l,r), post_tax_price(cost)
(b) Increases reusability and readability; same conical function can be reused for other tent types.
(c) def post_tax_price(cost): tax = 0.18 * cost; net_price = cost + tax; return(net_price)
(d) By importing the module containing the function or copying the function definition.

Case 2

(a) 0
(b) trafficLight() calls light(signal)
(c)
python def light(colour): if colour == "RED": return 0 elif colour == "YELLOW": return 1 else: return 2 (d) Python executes code top to bottom; function must be defined before it is called, otherwise NameError occurs.

All questions are answerable from the NCERT chapter text. Reviewed by GFIS faculty.