Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

GD GOENKA SIGNATURE SCHOOL

WORKSHEET III – FUNCTIONS & FILE HANDLING


CLASS XII – COMPUTER SCIENCE

1. Function name must be followed by _________


2. keyword is used to define a function _________
3. Function will perform its action only when it is _________________
4. Which of the following components are part of a function header in Python?
a. Function Name b. Return Statement c. Parameter List d. Both a and c
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. Which of the following is the reason to use Functions?
a) Reduce program size b) Avoiding ambiguity
c) More easily understandable d) All of the above

7. What is Indentation?

a)The blank space in the beginning of a statement within a block.


b)The authorization used by computer to provide access to code.
c)the bracket at the end .
d)The ending space used by computer at the end of statement.

8. Write statement to call the function.


def Add():
X = 10 + 20
print(X)
#statement to call the above function
9. Write the function name :
def Add(X,Y):
Z = X+Y
print(Z)
10. Write the parameters of the function:
def Add(X,Y):
Z = X+Y
return Z
11. What will be the output of following code?
def Cube(n):
print(n*n*n)
12. What is a function? How is it useful?
13. What is an argument? Give an example.
14. What is the utility of the built-in function?
15. What all information does a function header give you about the function?
16. Write the term suitable for following description:
(a) A name inside the parentheses of a function header that can receive a value.
(b) An argument passed to a specific parameter using the parameter name.
(c) A value passed to a function parameter.
(d) A value assigned to a parameter name in the function header.
(e) A value assigned to a parameter name in the function call.
(f) A name defined outside all function definitions.
(g) A variable created inside a function body.

17. Write a function called calculate_area() that takes base and height as input arguments and
returns area of a triangle as an output. The formula used is:
Triangle Area = 1/2*base*height
18. Write the use and syntax for the following methods:
a) open()
b) read()
19. Write the file mode that will be used for opening the following files. Also, write the Python
statements to open the following files:
a) a text file “example.txt” in both read and write mode
b) a text file “try.txt” in append and read mode
20. Differentiate between actual parameter(s) and a formal parameter(s) with a suitable
example for each.

You might also like