0% found this document useful (0 votes)
6 views

Competency Based Worksheet 02 on Python Functions

This document is a competency-based question bank focused on Python functions, containing multiple-choice, true/false, assertion/reason, error finding, and output prediction questions. It tests knowledge on user-defined functions, default parameters, and function calls, along with identifying and correcting syntax errors in Python code. The questions are structured to assess both theoretical understanding and practical coding skills.

Uploaded by

anshusagar123098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Competency Based Worksheet 02 on Python Functions

This document is a competency-based question bank focused on Python functions, containing multiple-choice, true/false, assertion/reason, error finding, and output prediction questions. It tests knowledge on user-defined functions, default parameters, and function calls, along with identifying and correcting syntax errors in Python code. The questions are structured to assess both theoretical understanding and practical coding skills.

Uploaded by

anshusagar123098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

COMPETENCY BASED QUESTION BANK - 2

Python Functions

MULTIPLE CHOICE BASED QUESTIONS

1 The function which is defined by programmer and not available already in program is : 1

a. Library Function b. Customised Function


c. User Defined function d. Predefined Function

2 What will be the output of the following code? 1

def hello(name, message="Welcome"):


print(name, message)

hello("Anjali")

a. Anjali b. Anjali Welcome


c. Welcome Anjali d. Error due to missing parameter

3 Which of the following function calls is incorrect if the function is defined as: 1

def calculate(a, b=2, c=3):


return a + b + c

a. calculate(1) b. calculate(1, 4)
c. calculate(1, c=4) d. calculate(b=3, 1, c=2)

4 What will be the output of the following code? 1

def greet():
name = "Python"
return name
print(greet())

a. Python b. greet c. name d. Error

5 Which of the following is a correct example of a function with default parameters? 1

a. def add (x, y=5): b. def add (x=5, y):


c. def add (x y=5): d. def add (default x, y):

TRUE / FALSE BASED QUESTIONS

6 State whether the following given statement is True or False : 1

A Python function does not reduce the code redundancy.

7 State whether the following given statement is True or False : 1

random() function never returns an integer value.

8 State whether the following given statement is True or False : 1

In Python, keyword arguments must follow positional arguments in a function call.


9 State whether the following given statement is True or False : 1

A function must always be called with all parameters provided, even if some have default
values.

10 State whether the following given statement is True or False : 1

A variable declared inside a function is called a global variable.

11 State whether the following given statement is True or False : 1

The keyword return is used to send a value back to the function caller.

ASSERTION (A) REASON (R) BASED QUESTIONS

Assertion (A) and Reason (R) based questions.


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.

12 Assertion (A) : A function is a building block of functions. 1


Reason (R) : Library functions are to import and use.

13 Assertion (A) : Importing a module with * makes the size of the program bigger. 1
Reason (R) : Python interpreter imports the module function code in the program before
execution.

14 Assertion (A) : In a Python function call, you can mix positional and keyword arguments. 1
Reason (R) : Python allows keyword arguments to be passed before positional arguments.

15 Assertion (A) : Default arguments in a function must be placed after all non-default 1
arguments.
Reason (R) : Python uses left-to-right evaluation for function arguments.

16 Assertion (A) : A function can return multiple values in Python. 1


Reason (R) : Python allows returning a tuple from a function.

17 Assertion (A) : Global variables can be accessed inside functions. 1


Reason (R) : Any variable inside a function is considered global by default.

ERROR FINDING BASED QUESTIONS

18 Rewrite the following code in python after removing all syntax error(s). Underline each 2
correction done in the code.

DEF calculate_sum(numbers)
sum = 0
for number in numbers:
sum = number
return Sum

print(call calculate_sum([1, 2, 3, 4, 5]))

19 Rewrite the following code in python after removing all syntax error(s). Underline each 2
correction done in the code.

def greet(name)
message = "Hello, " + name
return message

def farewell(name):
return "Goodbye " + name

print(greet(123)
print(farewell(456)
greet("John"

20 Identify the error in the following function definition or call: 1

def show(msg="Hello", name):


print(name, msg)

show("Ravi")

21 Identify the error in the function call: 1

def display(name, age=18):


print(name, age)

display(age=20, "Karan")

22 The following python code contains error(s). Rewrite the correct code and underline the 2
corrections made by you

def fun(a, b=3, c) :


Return a + b + c

x = fun (10, 20)


print(x)

23 The following python code contains error(s). Rewrite the correct code and underline the 2
corrections made by you

DEF test ( ) :
x=x+1
return x
print(x)

test ( )

FINDING OUTPUT(s) BASED QUESTIONS

24 What will be the output of the following code ? 3

def calculate_total(price, quantity=1, discount=0):


total = price * quantity
total -= total * (discount / 100)
return total

print(calculate_total(100))
print(calculate_total(100, 2))
print(calculate_total(100, 2, 10))

25 Predict the output : 3

def combine(a, b, sep=" "):


return str(a) + sep + str(b)

def wrapper():
print(combine("Hello", "World"))
print(combine("Python", "Programming", sep=" - "))
print(combine(10, 20, sep=":"))

wrapper()

26 What will be the output of the following code? 1

def info(name, grade="A", city="Delhi"):


print(name, grade, city)

info("Nina", city="Mumbai")

27 What will be printed ? 1

def func(x, y=5, z=10):


print("x:", x, "y:", y, "z:", z)

func(3, z=20)

28 What will be the output of the following code ? 1

x = 10
def show():
x=5
print(x)
show()
print(x)

29 What will be the output of the following code ? 1

def multiply(a, b=2):


return a * b

print(multiply(3))

You might also like