CBSE · Class 12 · Computer Science

Class 12 Functions Mock Test (CBSE)

6 practice questions from Functions, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.

Topics in Functions

  • Types of functions
  • User defined functions
  • Arguments and parameters
  • Default parameters
  • Positional parameters
  • Functions returning values
  • Flow of execution
  • Scope of a variable: local and global
  • Python standard library

Functions practice questions with answers

  1. Q1Multiple choice1 mark
    Consider the following Python code: def show(x, y, z): return (x - y)*z print(show(8, 2, 3)) What is the output of the program?
    1. (a)2
    2. (b)-18
    3. (c)9
    4. (d)18
    Show answer and step marks
    1. Correct option: (d) 18+1
    Answer: (d)
  2. Q2Multiple choice1 mark
    Consider the following Python code: def pay(basic, bonus=500): return basic + bonus print(pay(12000)) Which statement correctly explains why the call pay(12000) works?
    1. (a)The function raises an error because only one argument is given for two parameters, so the call is invalid.
    2. (b)The argument 12000 is copied into bonus, and basic takes the default value 500.
    3. (c)The default value of bonus is used only when bonus is given as the first argument in the call.
    4. (d)The parameter bonus takes its default value 500 because no value is passed for it in the call.
    Show answer and step marks
    1. Correct option: (d) The parameter bonus takes its default value 500 because no value is passed for it in the call.+1
    Answer: (d)
  3. Q3Multiple choice1 mark
    Consider the following Python code: def area(length, width): return length × width print(area(4, 7)) In the function call area(4, 7), the values 4 and 7 are called
    1. (a)parameters
    2. (b)arguments
    3. (c)return values
    4. (d)local variables
    Show answer and step marks
    1. Correct option: (b) arguments+1
    Answer: (b)
  4. Q4Short answer2 marks
    A Python program contains a function definition and, further down, a statement that calls that function. Distinguish the flow of execution at the point where the function is defined from the flow of execution at the point where it is called.
    Show answer and step marks
    1. At the definition, the interpreter only records the function; its body is not executed and control moves to the next statement after the definition.+1
    2. At the call, control jumps to the first statement of the function body, executes the body, and then returns to the statement immediately after the call.+1
    Answer: At definition, the body is only stored and not run, so control simply passes to the next statement. At a call, control transfers into the function body, runs it, and then returns to the statement after the call.
  5. Q5Short answer2 marks
    A railway ticket counter uses a Python program to calculate the fare for a train passenger. The fare is Rs 2 for each km travelled, plus a fixed booking charge of Rs 10 on every ticket. (a) Write a Python function named fare that takes the distance km as a parameter and returns the total fare. [1] (b) Write the statement that calls fare with a distance of 50 km and stores the value returned by the function in a variable amount. [1]
    Show answer and step marks
    1. (a) Function header def fare(km): with km as the parameter+0.5
    2. (a) return 2*km + 10, i.e. the total fare is given back using return, not printed+0.5
    3. (b) amount = fare(50), so the returned value is stored in amount+1
    Answer: (a) def fare(km): return 2*km + 10 (b) amount = fare(50)
  6. Q6Short answer3 marks
    Answer the following about the Python standard library. (a) Define the Python standard library in one sentence. [1] (b) Name the standard library module that provides the function \sqrt{}. [1] (c) Name the standard library module that provides the function randint(), which generates random integers. [1]
    Show answer and step marks
    1. (a) The Python standard library is a collection of built-in modules, installed with Python, that provide ready-made functions and constants.+1
    2. (b) \sqrt{} is provided by the math module (imported with import math).+1
    3. (c) randint() is provided by the random module.+1
    Answer: (a) A collection of built-in, ready-made modules installed with Python; (b) math module; (c) random module

Take a full Functions test

PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.

  • 15 min10 marks
  • 30 min20 marks
  • 1.5 hr40 marks
  • 3 hr80 marks
See a sample marked answer sheet

Get your Functions answers marked

Sign in, pick this chapter and a length, write the test on paper and get every step marked.

Sign in to take this test

More Class 12 Computer Science mock tests