AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Computer Science

Python Revision

Standard difficulty · 20 questions · 40 marks · Time: 41 minutes

Name: Date: Score: ____ / 40

Show your working for Sections B and C. Answers are on the last page — try every question first!

Section A — Choose the correct answer8 × 1 = 8 marks
1.
Which of these Python types is immutable?
  1. dictionary
  2. set
  3. list
  4. tuple
2.
What does this print?
s = 'SCHEDULE'
print(s[3:])
  1. ELUDE
  2. SCHEDU
  3. EDULE
  4. EUE
3.
What does this print?
s = 'data never sleeps at night'
print(s.capitalize())
  1. Data never sleeps at night
  2. DATA NEVER SLEEPS AT NIGHT
  3. data never sleeps at night
  4. Data Never Sleeps At Night
4.
What does this print?
L = [24, 26, 34, 6]
L.sort()
L.pop()
L.append(58)
print(L)
  1. [6, 24, 26, 58]
  2. [24, 26, 34, 6]
  3. [24, 26, 58]
  4. [6, 24, 26, 58, 24]
5.
What does this print?
T = (18, 12, 1, 22, 15, 15)
print(len(T * 3), max(T))
  1. 18 1
  2. 18 22
  3. 9 22
  4. 6 22
6.
What does this print?
s = 'MONitOrS'
c = 0
for ch in s:
    if ch.isupper():
        c = c + 1
print(c)
  1. 6
  2. 4
  3. 5
  4. 3
7.
What does this print?
d = {'litchi': 75, 'papaya': 60, 'grapes': 85}
d['papaya'] = d['papaya'] + 20
d['guava'] = 80
print(sum(d.values()))
  1. 300
  2. 340
  3. 320
  4. 240
8.
What does this print?
L = [39, 30, 34, 32]
print(L * 4 == L + L + L + L, len(L * 4))
  1. True 16
  2. False 16
  3. True 8
  4. True 4
Section B — Short answer8 × 2 = 16 marks
9.
What is the difference between a list and a tuple?
10.
What does this print?
s = 'MOUNTAIN'
print(s[3::2])
11.
What does this print?
L = [20, 22, 31, 8]
L.pop(2)
L.sort()
L.remove(20)
print(L)
12.
What does this print?
s = 'schEDULE'
c = 0
for ch in s:
    if ch not in 'aeiouAEIOU':
        c = c + 1
print(c)
13.
What does this print? Give (a) the first line (b) the second.
M = [[28, 14, 5], [15, 1, 3], [1, 15, 19]]
print(M[2][0])
s = 0
for x in M[2]:
    s = s + x
print(s)
14.
What does this print?
word = 'lette'
d = {}
for ch in word:
    d[ch] = d.get(ch, 0) + 1
print(d)
15.
What does this print?
d = {'apple': 70, 'orange': 40, 'grapes': 25}
d['orange'] = d['orange'] + 15
d['guava'] = 70
print(d)
16.
What does this print? Write the numbers separated by commas.
L = [72, 98, 27, 79, 38, 70, 85]
L.sort(reverse=True)
for x in L[:2]:
    print(x)
Section C — Word problems4 × 4 = 16 marks
17.
Explain indexing and slicing of strings with examples, including negative indices.
18.
Write the output of each program.
(a)
s = 'keep calm and write code'
print(s.capitalize())
(b)
s = 'MOUNTAIN'
print(s[::3])
(c)
L = [11, 35, 14, 26]
L.append(43)
L.reverse()
L.pop(0)
print(L)
19.
Trace this program. Give (a) the first line it prints (b) the second (c) the third.
s = 'candle kite forest river ladder'
words = s.split()
longest = ''
initials = ''
for w in words:
    if len(w) > len(longest):
        longest = w
    initials = initials + w[0].upper()
print(len(words))
print(longest)
print(initials)
20.
Trace this program. (a) What is the first line printed? (b) The second? (c) The third?
marks = {'Vikram': 95, 'Rahul': 76, 'Dev': 73, 'Meera': 92, 'Ananya': 50}
count = 0
for name in marks:
    if marks[name] >= 73:
        count = count + 1
best = max(marks, key=marks.get)
print(count)
print(best)
print(sum(marks.values()))
AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Computer Science

Answer key

Python Revision · AW-12CS-PYR-2026-V1 · For parents — fold back or tear off before handing the sheet to your child.

QAnswerWorking
1(d) tuple—
2(c) EDULEcount indices from 0; the stop index is not included
3(a) Data never sleeps at nightcapitalize() changes only the first character of the string
4(a) [6, 24, 26, 58]apply each method to the list in turn
5(b) 18 22T * 3 repeats the tuple, so it has 18 items
6(c) 5check each character in turn
7(c) 320assigning to an existing key changes it; a new key is added at the end
8(a) True 16L * 4 repeats the list 4 times, so it has 16 items
9A list is mutable (its items can be changed, added or removed) and is written in [ ]; a tuple is immutable and is written in ( ).—
10NANcount indices from 0; the stop index is not included
11[8, 22]apply each method to the list in turn
125check each character in turn
13(a) 1; (b) 35M[i][j] is row i, column j, both counted from 0
14{'l': 1, 'e': 2, 't': 2}a key is added the first time a letter is seen; get(ch, 0) gives 0 for a new letter
15{'apple': 70, 'orange': 55, 'grapes': 25, 'guava': 70}assigning to an existing key changes it; a new key is added at the end
1698, 85sorted largest first: 98, 85, 79, 72, 70, 38, 27
17Characters are numbered from 0 at the left and from −1 at the right. s[i] gives one character; s[a:b] gives the characters from a up to b − 1; s[a:b:k] takes every kth one; s[::−1] reverses. For s = 'PYTHON', s[1:4] is 'YTH', s[−2:] is 'ON'.indices, slices with start/stop/step, negative indices, examples
18(a) Keep calm and write code; (b) MNI; (c) [26, 14, 35, 11]capitalize() changes only the first character of the string
19(a) 5; (b) candle; (c) CKFRLwords: candle, kite, forest, river, ladder; the first longest word is kept because > is strict
20(a) 4; (b) Vikram; (c) 386marks of at least 73: Vikram, Rahul, Dev, Meera; highest 95