C12 Ans-Key 70m 1-10
C12 Ans-Key 70m 1-10
C12 Ans-Key 70m 1-10
Section – B
19. Write a function to inspect an element from the stack.
20. Write a function cust_data() to ask user to enter their names and age to store data in customer.txt
file.
Ans: 22 # 40 # 9 # 13 #
24. Write a Python program that accepts two integers from the user and prints a message saying if first
number is divisible by second number or if it is not.
Ans:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a % b == 0:
print(a, "is divisible by", b)
else:
print(a, "is not divisible by", b)
25. Write a python program to print the following pyramid
A
B B
C C C
D D D D
E E E E E
def pypart(n):
for i in range(0, n):
for j in range(0, i+1):
print("* ",end="")
print("\r")
n=5
pypart(n)
26. What is the difference between remove( ) and pop ( )
Section – C
27. Draw a flow chart for if-elif-else conditional statement.
28. Rewrite the following code in Python after removing all syntax error(s).
Underline each correction done in the code.
STRING = “WELCOME”
NOTE=””
for S in range(0,7):
print STRING[S]
print S,STRING
29. Find the output of the following Python code:
def Change(P, Q=30)
P=P+Q
Q=P–Q
print(P, “#”,Q)
return P
R = 150
S = 100
R = Change(R,S)
print (R,”#”,S)
S = Change(S)
Ans:
250 # 150
250 # 100
130 # 100
30. Write a program in Python to read lines from a text file DIARY.TXT, and display those lines,
which are starting with the letter ‘M’
31. . Difference between Indexing and Slicing
Section – D
31. a) Praveena of class 12 is writing a program to create a CSV file “clients.csv”. She has written the
following code to read the content of file clients.csv and display the clients’ record whose name begins
with “A‟ and also count as well as show no. of clients with the first letter “A‟ out of total records. As
a programmer, help her to successfully execute the given task.
Consider the following CSV file (clients.csv):
Read the questions given below and fill in the gaps accordingly:
1.State the module name required to be written in Line-1. csv
2.Mention the name of the mode in which she should open a file. r mode
3.Fill in the gaps for given statements – Line-2 and Line-3. Line 2 – “client.csv”,”r” and Line 3 –
reader
b) The explicit conversion of an operand to a specific type is called Type casting.
32. Write a Program in Python that defines and calls the following user defined functions:
a) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of
a list with field elements as empid, name and mobile to store employee id, employee name and
employee salary respectively.
b) COUNTR() – To count the number of records present in the CSV file named ‘record.csv’.
Section – E
34. Consider the following code and answer the questions that follow:
Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children Stories'}
Library ={'5':'Madras Diaries','6':'Malgudi Days'}
(1) Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime Thriller’. He has
written the following command:
>>> Book[‘Crime’] = ’Crime Thriller’
But he is not getting the answer. Help him choose the correct command:
a) Book[2]=’Crime Thriller’ b) Book[3]=’Crime Thriller’ c) Book[2]=(’Crime Thriller’)
d) Book[3] =(‘Crime Thriller’)
2) The command to merge the dictionary Book with Library the command would be:
a) d=Book+Library b) print(Book+Library) c) Book.update(Library)
d) Library.update(Book)
3) What will be the output of the following line of code:
>>> print(list(Library))
a) [‘5’,’Madras Diaries’,’6’,’Malgudi Days’] b) (‘5’,’Madras Diaries’,’6’,’Malgudi Days’)
c) [’Madras Diaries’,’Malgudi Days’] d) [‘5’,’6’]
4. In order to check whether the key 2 is present in the dictionary Book, Ramesh uses the following
command:
>>> 2 in Book
He gets the answer ‘True’. Now to check whether the name ‘Madras Diaries’ exists in the dictionary
Library, he uses the following command:
>>> ‘Madras Diaries’ in Library
But he gets the answer as ‘False’. Select the correct reason for this:
a) We cannot use the in function with values. It can be used with keys only.
b) We must use the function Library.values() along with the in operator
c) We can use the Library.items() function instead of the in operator
d) Both b and c above are correct.
35. Arun during practical examination of computer science, has been assigned an incomplete search( )
function
to search in a pickled file student.dat. The file student.dat is created by his teacher and the following
information
is known about the file.
• File contain details of students in [rool_no, name_marks] format.
• File contains detail of 10 students(i.e from roll_no 1 to 10) and separate list of each student is
written in the binary File using dump ( ).
Arun has been assigned the task to complete the code and print details of roll number 1.
def search ( ):
f = open (“student.dat”, _______________) #statement 1
_______: # statement 2
while True:
rec = pickle._______ # statement 3
if ( _______): # statement 4
print (rec)
expect: pass
f.close( )
Q1. In which mode Arun should open the file in statement-1
a) r b) r+ c) rb d) wb
Q2. Identify the suitable code to be used at blank space in statement-2
a) if(rec[0] = = 1) b) for I in range(10) c) try d) pass
Q3. Identify the function (with argument), to be used at blank space in line marked as statement-3
Ans: load(f)
Q4. What will be the suitable code for the blank space in line marked as statement – 4
Ans: rec[0] = = 1