Completed
Class 12 CS – Complete Python Test
Questions From This Challenge
Q1mcq1 mark
What will be the output? def calculate(a, b=4): b = b + 2 return a + b x = calculate(8) y = calculate(x, 3) print(x, y)
14 19 ✓
14 17
12 17
12 19
Q2mcq1 mark
What will be the output? def change(a, b): a = a + 5 b = b + a return b x = 4 y = 6 z = change(x, y) print(x, y, z)
9 15 15
4 6 19
4 6 15 ✓
9 15 19
Q3mcq1 mark
What will be the output? x = 8 def update(): global x x = x + 4 return x * 2 a = update() b = update() print(a, b, x)
24 32 16 ✓
24 48 24
16 24 16
12 16 24
Q4mcq1 mark
What will be the output? def test(a, b=6): return a * b print(test(3), test(3, 4))
18 12 ✓
12 18
18 18
9 12
Q5mcq1 mark
What will be printed? try: a = 12 b = int("4") print(a // b) except ValueError: print("V") except ZeroDivisionError: print("Z") finally: print("F")
3 F ✓
3
V F
Z F
Q6mcq1 mark
A text file contains: COMPUTER What will be printed? f = open("data.txt", "r") f.seek(4) print(f.read(2)) f.close()
CO
PU
UT ✓
TE
Q7mcq1 mark
A text file contains: ABCDEFGHIJ What will be printed? f = open("data.txt", "r") f.read(3) print(f.tell()) f.close()
2
3 ✓
4
10
Q8mcq1 mark
A text file contains: PYTHON What will be the final content of the file? f = open("data.txt", "r+") f.seek(2) f.write("AB") f.close()
PYABON ✓
ABPYTHON
PYTHONAB
PYABTHON
Q9mcq1 mark
What will be printed? import pickle f = open("data.dat", "wb") pickle.dump(12, f) pickle.dump(18, f) pickle.dump(25, f) f.close() f = open("data.dat", "rb") a = pickle.load(f) pickle.load(f) c = pickle.load(f) print(c - a) f.close()
6
7
13 ✓
25
Q10mcq1 mark
What will be printed? f = open("data.txt", "w+") f.write("ABCDEFG") f.seek(4) x = f.read(2) print(x) f.close()
DE
EF ✓
FG
CD
Q11mcq1 mark
What will be printed? import csv f = open("marks.csv", "r") r = csv.reader(f) next(r) total = 0 for row in r: if int(row[1]) > 70: total = total + 1 print(total) f.close()
1
2 ✓
3
150
Q12mcq1 mark
What will be printed? import pickle f = open("data.dat", "wb") pickle.dump(10, f) pickle.dump(20, f) f.close() f = open("data.dat", "rb") a = pickle.load(f) f.close() f = open("data.dat", "rb") b = pickle.load(f) print(a + b) f.close()
10
20 ✓
30
40
Q13mcq1 mark
Consider the following CSV data: Roll,Marks 1,65 2,80 3,75 What will be printed? import csv f = open("marks.csv", "r") r = csv.reader(f) next(r) total = 0 for row in r: if int(row[1]) > 70: total = total + 1 print(total) f.close()
1
2 ✓
3
150
Q14mcq1 mark
What will be printed? import csv f = open("data.csv", "w", newline="") w = csv.writer(f) w.writerow(["A", 15]) w.writerow(["B", 25]) w.writerow(["C", 35]) f.close() f = open("data.csv", "r") r = csv.reader(f) row = next(r) row = next(r) print(row[0], row[1]) f.close()
A 15
B 25 ✓
C 35
B 35
Q15mcq1 mark
What will be printed? stack = [10, 20, 30] x = stack.pop() stack.append(x + 10) stack.pop() stack.append(5) print(stack[-1])
20
30
40
5 ✓