Holiday Homework Grade XII Computer Science
Holiday Homework Grade XII Computer Science
Grade XII
Question Bank
Functions in Python
General Instructions:
a) range(0, 5)
b) 0, 1, 2, 3, 4
c) [0, 1, 2, 3, 4]
Q21. The process of dividing a computer program into separate independent blocks
of code with different names and specific functionalities is known as ______________.
a) Mode Programming
b) Modular Programming
c) Division Programming
d) None of the above
Q22. Advantage of using function is/are
a) Reusability of Code
b) Divide a complex problem into simpler ones.
c) Reduces chances of error.
d) All of the above
Q23. _____________ can be defined as a named group of instructions that accomplish
a specific task when it is invoked.
a) Function
b) Variable
c) Global Variable
Q24. A function can be called ________ from anywhere in the program.
a) Single time
b) Two times
c) repeatedly
d) None of the above
Q25. What is the purpose of following statement?
def check():
a) Calling a function
b) Defining a function
c) None of the above
d) Both of the above
Q26. Use of functions in a program makes it __________
a) more organised
b) easy to read
c) both of the above
d) None of the above
Q27. Functions which can be used directly in a program are stored in ________
library.
a) Standard
b) Main
c) Sub
d) Union
Q28. A function defined to achieve some task as per the programmer's requirement is
called a __________
a) Standard function
b) User defined Function
c) Built in Function
d) None of the above
Q29. A function definition begins with ___________
a) def
b) define
c) create
d) New
Q30. Function header always ends with a __________
a) comma
b) semicolon
c) colon
d) period
import math
def python_lib():
s = “Computer Science with Python”
print(s.swapcase())
print(s.title())
print(s.split())
print(s.replace(‘with’,’-‘))
Q-3. Which of the following command is used to open a file “c:\temp.txt” in append-
mode?
B. outfile = open(“c:\\temp.txt”, “rw”)
C. outfile = open(“c:\temp.txt”, “w+”)
D. outfile = open(“c:\\temp.txt”, “r+”)
E. outfile = open(“c:\\temp.txt”, “a”)
Q-4. Which of the following statements are true regarding the opening modes of
a file?
A. When you open a file for reading, if the file does not exist, an error occurs.
B. When you open a file for writing, if the file does not exist, an error occurs.
C. When you open a file for reading, if the file does not exist, the program will open an
empty file.
D. When you open a file for writing, if the file does not exist, it is searched in parent
folder.
Q-5. Which of the following commands can be used to read “n” number of characters
from a file using the file object <file>?
A. file.read(n)
B. n = file.read()
C. file.readline(n)
D. file.readlines()
Q-6. Which of the following commands can be used to read the entire contents of a
file as a string using the file object <tmpfile>?
A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()
Q-7. Which of the following commands can be used to read the next line in a file
using the file object <tmpfile>?
A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()
Q-8. Which of the following commands can be used to read the remaining lines in a
file using the file object <tmpfile>?
A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()
Q-10. Which of the following command is used to open a file “c:\temp.txt” for writing
in binary format only?
A. outfile = open(“c:\temp.txt”, “w”)
B. outfile = open(“c:\\temp.txt”, “wb”)
C. outfile = open(“c:\temp.txt”, “w+”)
D. outfile = open(“c:\\temp.txt”, “wb+”)
file1.write("Hello \n")
file1.writelines(L)
file1.close() #to change file access modes
file1 = open("myfile.txt","r+")
print(file1.read(10))
A. This is De
B. Hello
This
C. Hello
This is
D. Hello
This is Delhi
Subjective Questions
1. Write a program to read a file line by line and print it. (3)
2. Write a python program to read a file and print the contents after removing
all punctuation marks. (3)
3. What is the following code doing? (3)
file =open(“contacts.csv”,”a”)
name=input(“enter name”)
ph=input(“enter ph no.”)
file.write(name+”,”+ph+”\n”)