C12 Ans-Key 70m 1-10

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

I.

Answer the following: 18 X 1 = 18


1. Which of the following is an invalid datatype in Python?
a) Set b) None c) Integer d) Real
2. Consider the given expression: not True and False or True
a) True b) False c) NONE d) NULL
3. Which of the following mode in file opening statement results or generates an error if the file does
not exist?
a) a+ b) r+ c) w+ d) None of the above
4. Which of the following statement(s) would give an error after executing the
following code?
S="Welcome to class XII" # Statement 1
print(S) # Statement 2
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5
a) Statement 3 b) Statement 4 c) Statement 5 d) Statement 4 & 5
5. which of the following statements is not true for parameter passing to function?
a) you can pass positional arguments in any order.
b) you can pass keyword argument in any order.
c) you can call a function with positional any keyword arguments.
d) positional arguments must be before keyword arguments in a function.

6. What will the following expression be evaluated to in Python?


print(15.0 / 4 + (8 + 3.0))
a) 14.75 b) 14.0 c) 15 d) 15.5
Directions: In the following questions, A statement of assertion (A) is followed by a statement of
Reason (R). Mark the correct choice as.
a) Both A and R are true and R is the correct explanation of A
b) Both A and R are true and R is not correct explanation of A
c) A is true but R is false
d) A is false but R is true
7. Assertion(A): Lists can be change after creation.
Reason(R): Lists are mutable
Ans: A
8. Assertion(A): Text file stores information in ASCII or Unicode characters.
Reason(R): In text file, there is no delimiter for a line.
Ans: C
9. Assertion(A): CSV file is a human readable text file where each line has a number of fields, separated
by commas or some other delimiter
Reason(R): writerow() function can be used for writing into writer object.
Ans: B
10. This method is used to load(unpickling) data from a binary file.
a) load( ) b) dump ( ) c) Seek ( ) d) tell ( )
11. Convert the expression into postfix: (A+B)*(C*DE)*F/G
Ans: AB+CDE**F*G/
12. What are the two main types of functions?
i) Custom function ii) Built-in-function iii) User define function d) System function
a) i and ii b) ii and iii c) iii and iv d) i and iv
13. Find the output of the following:
T = (10,30,2,50,100,65)
a) print (max(T)) 100 b) print (min(T)) 2
14. Identify the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
a) 12.0 b) 13.0 c) 14.0 d) 15.0
15. Syntax of seek function in Python is myfile.seek(offset, reference_point) where myfile is the file
object. What is the default value of reference_point?
a) 0 b) 1 c) 2 d) 3
16. Which type of error occurs when the rules of programming language are misused – Syntax error
17. What will be the output of the following:
x = 12
for in in x:
print(i)
Ans: Error int type non-iteratable
18. Which of the following sequences would be generated in the given line of code in shell?
range (5, 0, -2)
Ans: range (5, 0, -2)

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.

21. a. Given is a Python string declaration:


myexam="@@CBSE Examination 2022@@"
Write the output of: print(myexam[::-2])
Ans: @20 otnmx SC@
22. The code given below accepts a number as an argument and returns the reverse number. Observe
the following code carefully and rewrite it after removing all syntax and logical errors. Underline all
the corrections made.
23. Predict the output of the Python code given below:

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’.

33. a) Convert the following while loop into for loop:


i=0
while i < 100:
if i % 4 = = 2:
print (i, “is even”)
else:
print(i, “is odd”)
i=i+1
Ans:
for i in range(100):
if i % 2 = = 0:
print(i,”is even”)
else:
print(i,”is odd”)

b) What is default parameter? How is it specified?


Ans: Python has a different way of representing syntax and default values for function arguments.
Default values indicate that the function argument will take that value if no argument value is passed
during the function call. The default value is assigned by using the assignment(=) operator of the form
keywordname=value.

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

Prepared by Archana S Co-ordinator’s signature

You might also like