CS Xii
CS Xii
CLASS-XII
SUBJECT: COMPUTER SCIENCE (083)
2. Which of the following operator cannot be used with string data type?
a) + b) * c) += d) **
3. Which of the following properly expresses the precedence of operators (using parentheses) in the
following expression:
5*3 > 10 and 4+6==11
a) ((5*3) > 10) and ((4+6) == 11) c) (5*(3 > 10)) and (4 + (6 == 11))
b) ((((5*3) > 10) and 4)+6) == 11 d) ((5*3) > (10 and (4+6))) == 11
7. Write a statement to send the file pointer to the end of file, consider FILE as file object.
a) FILE .seek(0) b) FILE .seek(0,1) c) FILE .seek(2,0) d) FILE .seek(0,2)
8. ________
File = open(‘a.csv’,”a”,newline=’’)
File.close()
Select the option to fill in the blank in above code to include the required module.
a) import CSV b) from csv import * c) import csv d) both b) & c)
10. Identify the correct option to delete the last value 25 from the list
L=[22,44,66,[80,20],15,25]
a) L.pop() b) L.pop(-1) c) L.remove(25) d) All of these
1
11. The order of passing arguments in a function call can be changed through ______ argument.
a) positional b) keyword c) named d) both b) & c)
19. If the content of the file “wish.txt” is – “Happy”, then what will be the content of the file after
executing the following statements –
f=open(“wish.txt”, ‘w’)
f.write(“Birthday”)
f.close()
a) Happy Birthday b)HappyBirthday c)Happy d)Birthday
20. Select the jump statements from the following:
a). continue b). break c). return d). All of these
22. Which of the following functions is required to write data in a csv file?
a)writerow( ) b)writerows( ) c)writer( ) d)all of these
23. Select the appropriate option to read first 3 characters from a text file represented by FR object.
a) FR.read(3) b)FR.readline(3) c)FR.readline(2) d)both a) & b)
2
24. A csv file Info.csv contains following data about code and number of students enrolled in different
subjects and each row data is separated by tab stop.
83 CS 1123
65 IP 1098
302 HINDI 2500
Now select the correct option for code-1 in the following:.
import csv
with open(“Demo.txt”,”r”,newline=’’) as P:
Q=csv.reader(P,_______)#code 1
P.close()
a) delimiter=’/t’ b) delimiter=’\t’ c) delimiter=tab d) sep=’\t’
27. Rajat is a class 12 student and he has created a text file named names.txt. He wants to display all
the names contained in the text file. He has written one of the following codes and succeeded in
getting the output. Guess which among the following option might have given the correct output:
a. names = open("names.txt", "r")
for line in names:
print(names)
b. names = open("names.txt", "r")
for line in names:
print("line")
c. names = open("names.txt", "r")
for line in names:
print(line)
d. names = open("names.txt", "r")
for names in line:
print(line)
29. Suppose content of 'Myfile.txt' is ‘Time and Tide wait for none’
What will be the output of the following code?
myfile = open("Myfile.txt")
p=0
x = myfile.read()
for y in x:
if y in ‘Tt’:
p=p+1
print(p)
myfile.close()
a. 2 b. 3 c.4 d. None
33. Consider the following program. What is the correct flow of execution of statements?
1) def fun1(m, n):
2) c=m+n
3) print(c)
4) return c
5) x = 10
6) y = 20
7) fun1(x,y)
8) print(“OK”)
(a) 1,2,3,4,5,6,7,8 (b) 1,5,6,7,1,2,3,4,8 (c) 1,5,6,1,2,3,4,7,8 (d) 7,8,1,2,3,4,5,6
34. What output will following function returns? Select the correct option.
def result():
return 2-10*(10+6)//5%2**3**2
a)30 b)-30 c)-32 d)2.0
4
X=100
def my_func(P=20, Q=30):
P+=10
Q = Q - 10
X=P+Q
return X
print(my_func(50),X)
a. 50 50 b. 50 100 c. 80 100 d. 80 80
5
a) [ ‘a’] b) ‘a’ c) [[‘a’]] d.any type
43. def Interest(p,c,t=2,r=0.09):
return p*t*r
Considering the above defined function ,which of following function call are legal.
1. Interest(p=1000,c=5)
2. Interest(r=0.05,5000,3)
3. Interest(500,t=2,r=0.05)
4. Interest(c=4,r=0.12,p=5000)
a). 1 , 2 and 4 b). 2 & 3 c). 1 &4 d). 3 & 4
44. Assertion (A): We can use a list as a key in a dictionary.
Reason(R): List is a mutable type and keys of dictionary must be an immutable type.
a) Both the A and R are true and R is the correct explanation for A
b) A is true and R is false and R is the correct explanation for A
c) A is false but the R is true and R is the correct explanation for A
d) Both the A and R are false
49.Krishna of class 12 is writing a program to input the details of games played at different venues
along with their prize money and store them in the csv file “games.csv” delimited with a ‘#’
character. As a programmer, help him to achieve the task.
import _________ # Line 1
f = open("games.csv","a",_________) # Line 2
fileWriter=csv.___________________ # Line 3
fileWriter.writerow(['GameName', 'PrizeMoney','Venue'])
while True:
gname = input("Enter Game Name :")
prize = int(input("Enter Prize Money :"))
venue = input("Enter Venue :")
record = __________________ # Line 4
fileWriter._________________ # Line 5
ans = input("Do u want to continue ? (y/n) :")
if ans!='y':
break
f.close()
Now select the appropriate option(i-iv) from the following questions.
(i) Fill in the blank in Line 1 to import appropriate module.
(a) pickle (b) csv (c) math (d) random
(ii) Fill in the blank in Line 3 to create writer object with separator as "#".
(a) writer(f,separator='#') (b) writer(f,delimiter='#')
(c) writer(delimiter='#',f) (d) writer(separator='#',f)
(iii) Fill in the blank in Line 2 to remove EOL character
(a) newline='\r\n' (b) newline='\n' (c) remove='EOL' (d) newline=""
(iv) Fill in the blank in Line 4 to store the input data in a List named record.
(a) record.append([gname,prize,venue] ) (b) append([gname,prize,venue])
(c) [gname,prize,venue] (d) (gname,prize,venue)
(v) Write the missing code in Line 5 to write the value of variable record to a CSV
File ‘games.csv’.
50. Write statement using built-in methods/functions to carry out following:
i) To know the frequency of E element in L list.
ii) To remove a given element E from a list L.
iii) To merge d1 dictionary with d2 dictionary.
iv) To store all the words of S string in a List L.
************************