0% found this document useful (0 votes)
125 views4 pages

Function - Worksheet 1 - 1 Marks

This document is a worksheet for Grade 12 Computer Science focusing on Python functions. It includes questions on function outputs, headers, calling functions, and assertions regarding function behavior. The worksheet tests understanding of concepts such as global variables, default arguments, and the return statement in Python.

Uploaded by

Divyanshi Patel
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)
125 views4 pages

Function - Worksheet 1 - 1 Marks

This document is a worksheet for Grade 12 Computer Science focusing on Python functions. It includes questions on function outputs, headers, calling functions, and assertions regarding function behavior. The worksheet tests understanding of concepts such as global variables, default arguments, and the return statement in Python.

Uploaded by

Divyanshi Patel
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

Grade: 12 Computer Science

Function - Worksheet - 1
1 Marks

1. Find and write the output of the following python code:


a=10
def call():
global a
a=15
b=20
print(a)
call()
2. Which of the following components is part of a function header in Python?
a. Function Name b. Return Statement c. Parameter List d. Both a and c
3. Which of the following function header is correct?
a. def cal_si(p=100, r, t=2) b. def cal_si(p=100, r=8, t)
c. def cal_si(p, r=8, t) d. def cal_si(p, r=8, t=2)
4. Which of the following is the correct way to call a function?
a. my_func() b. def my_func() c. return my_func d. call my_func()

5. What will be the output of the following Python code?


def add (num1, num2):
sum = num1 + num2
sum = add(20,30)
print(sum)
a. 50 b. 0 c. Null d. None
6. What will be the output of the following code?
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 – 10
return var1+var2
print(my_func(50),my_func())
a. 100 200 b. 150 300 c. 250 75 d. 250 300

Function - Worksheet – 1 - 1 Marks Page 1


7. Consider the code given below:

Which of the following statements should be given in the blank for #Missing Statement,
if the output produced is 110?
a. global a b. global b=100 c. global b d. global a=100
8. Write the output of the following Python code :
def Update(X=10):
X += 15
print('X = ', X)
X=20
Update()
print('X = ', X)
9. Which of the following statement(s) would give an error after executing the following
code?
def prod (int a): #Statement 1
d=a*a #Statement 2
print(d) #Statement 3
return prod #Statement 4
(a) Statement 1 and Statement 2 (c) Statement 1 and Statement 4
(b) Statement 1 and Statement 3 (d) Statement 2 and Statement 4
10. Assertion (A) :- A return statement returns a value as well as the control from a
function.
Reasoning (R) :- It is compulsory for all functions to have a return statement.
11. Assertion(A):-If the arguments in function call statement match the Number and
order of arguments as defined in the function definition, such arguments are called
positional arguments.
Reasoning(R):-During a function call, the argument list positional argument(s) must
occur after the default arguments.

Function - Worksheet – 1 - 1 Marks Page 2


13. Assertion (A): The local and global variables declared with the same name in the
function are treated same by the Python interpreter.
Reason (R): The variable declared within the function block is treated to be local variable
where as, the variable declared outside the function block will be referred to as global
variable.
14. Assertion (A): A variable declared as global inside a function is visible with changes
made to it outside the function.
Reasoning (R): All variables declared outside are not visible inside a function till they are
redeclared with global keyword.
15. Assertion (A):- If the arguments in a function call statement match the number and
order of arguments as defined in the function definition, such arguments are called
positional arguments.
Reasoning (R):- During a function call, the argument list first contains default
argument(s) followed by positional argument(s).
16. Assertion (A):- In Python, statement return [expression] exits a function.
Reasoning (R):- Return statement passes back an expression to the caller.A return
statement with no arguments is the same as return None.
17. Assertion (A):- If the arguments in a function call statement match the number and
order of arguments as defined in the function definition, such arguments are called
positional arguments. Reasoning
(R):- During a function call, the argument list first contains default argument(s) followed
by positional argument(s).
18. Assertion(A):Functionisdefinedasasetofstatementswrittenunderaspecificname in the
python code
Reason(R): The complete block (set of statements) is used at different instances in the
program as and when required, referring the function name. It is a common code to
execute for different values(arguments),provided to a function.
19. Assertion: The default value of an argument will be used inside a function if we do
not pass a value to that argument at the time of the function call.
Reason: the default arguments are optional during the function call. It overrides
the default value if we provide a value to the default arguments during function calls.
20. Assertion (A):- The default arguments can be skipped in the function call.
Reasoning (R):- The function argument will take the default values even if the values are
supplied in the function cal

Function - Worksheet – 1 - 1 Marks Page 3


21. Assertion(A):Key word arguments are related to the function calls
Reason(R): When you use keyword arguments in a function call, the caller identifies the
arguments by the parameter name
22. Assertion (A): The function definition calculate(a, b, c=1,d) will give error.
Reason (R): All the non-default arguments must precede the default arguments.
23. Assertion (A):- The number of actual parameters in a function call may not be equal
to the number of formal parameters of the function.
Reasoning (R):- During a function call, it is optional to pass the values to default
parameters
24. What will be output of following code:
X = 50
def funct(X):
X=2
funct (X)
print(“X is now: “, X)
a) X is now: 50 b) X is now: 2 c) Error d) None of the above
25. Which function header statement is correct:-
(a) def interest (prin, time=2, rate):
(b) def interest (prin=2000, time=2, rate):
(c) def interest (prin=2000; time=2; rate)
(d) def interest (prin, time=2, rate=0.10):

Function - Worksheet – 1 - 1 Marks Page 4

You might also like