Completed
Class XII Test A1.0
Questions From This Challenge
Q1output1 mark
What will be the output of the following Python code?
def process(a, b=4):
a = a + b
b = a - b
return a, b
x = 6
p, q = process(x, 3)
print(p - q)
print(x)
Correct output:
3
6Q2output1 mark
What will be the output of the following Python code?
def calculate(n):
if n % 2 == 0:
return n // 2
return n * 3 + 1
x = calculate(7)
print(calculate(x))
Correct output:
11Q3output1 mark
What will be the output of the following Python code?
def modify(a, b=5):
a = a + b
b = a * 2
return b - a
x = 4
print(modify(x))
print(modify(x, 2))
Correct output:
9
6Q4output1 mark
A text file "data.txt" contains the following line:
Computer Science
What will be the output of the following code?
f = open("data.txt", "r")
print(len(f.readline()))
f.close()
Correct output:
17Q5output1 mark
What will be the output of the following Python code?
f = open("data.txt", "w")
f.write("ABCDE")
f.close()
f = open("data.txt", "a")
f.write("FG")
f.close()
f = open("data.txt", "r")
f.seek(2)
print(f.read(3))
f.close()
Correct output:
CDEQ6output1 mark
A text file contains the following lines:
Python
SQL
CSV
Binary
What will be the output of the following code?
f = open("data.txt", "r")
x = f.readlines()
f.close()
print(len(x))
print(len(x[0].strip()) + len(x[2].strip()))
Correct output:
4
6Q7output1 mark
What will be the output of the following Python code?
import pickle
data = [12, 18, 25]
with open("data.dat", "wb") as f:
pickle.dump(data, f)
with open("data.dat", "rb") as f:
result = pickle.load(f)
print(result[0] + result[2])
Correct output:
37Q8output1 mark
A binary file contains the following records stored using pickle:
[101, "Amit", 72]
[102, "Riya", 81]
[103, "Karan", 75]
[104, "Neha", 68]
What will be the output of the following code?
import pickle
with open("student.dat", "rb") as f:
count = 0
while True:
try:
rec = pickle.load(f)
if rec[2] >= 75:
count = count + 1
except EOFError:
break
print(count)
Correct output:
2Q9output1 mark
A CSV file contains:
101,Amit,78
102,Riya,91
103,Karan,85
What will be the output of the following code?
import csv
with open("marks.csv", "r") as f:
reader = csv.reader(f)
total = 0
for row in reader:
marks = int(row[2])
if marks % 2 == 1:
total = total + marks
print(total)
Correct output:
254Q10output1 mark
What will be the output of the following Python code?
import csv
with open("data.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["A", 10])
writer.writerow(["B", 15])
writer.writerow(["C", 20])
with open("data.csv", "r") as f:
reader = csv.reader(f)
total = 0
for row in reader:
if int(row[1]) > 10:
total = total + int(row[1])
print(total)
Correct output:
35Q11mcq1 mark
A stack initially contains: [10, 20, 30, 40] where 40 is the TOP. The following operations are performed: POP() PUSH(50) POP() PUSH(60) PUSH(70) POP() What will be the final stack?
[10, 20, 30, 60] ✓
[10, 20, 30, 60, 70]
[10, 20, 30, 50, 60]
[10, 20, 30, 40, 60]
Q12output1 mark
What will be the output of the following Python code?
L = [3, 6, 9, 12, 15]
total = 0
for i in range(len(L)):
if i % 2 == 0:
for j in range(1, 3):
total = total + L[i] // j
else:
total = total - L[i]
print(total)
Correct output:
21Q13mcq1 mark
A relation has degree 6 and cardinality 120. Three new attributes are added. Then 25 tuples are deleted. Finally, one attribute is removed. What are the final values?
Degree 8, Cardinality 95 ✓
Degree 9, Cardinality 95
Degree 8, Cardinality 145
Degree 7, Cardinality 95
Q14mcq1 mark
A column is defined as CHAR(5). A value containing 3 characters is stored in it. Another column is defined as VARCHAR(5) and stores the same value. Which statement is correct?
Both columns become length 3.
CHAR has fixed length; VARCHAR has variable length. ✓
CHAR stores 3 characters; VARCHAR stores 5 characters.
Both have identical storage behaviour.
Q15output1 mark
What will be the output of the following Python code?
def calculate(x):
if x % 2 == 0:
return x // 2
else:
return x + 3
x = 5
for i in range(3):
x = calculate(x + i)
print(x)
Correct output:
7