Chapter 2_ Python Revision Tour II _ Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT _ KnowledgeBoat
Chapter 2_ Python Revision Tour II _ Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT _ KnowledgeBoat
Home / Class 12 - Computer Science with Python Sumita Arora / Python Revision Tour II
Chapter 2
Python Revision Tour II
Class 12 - Computer Science with Python Sumita Arora
Question 1
1. position
2. integer position
3. index
4. location
Answer
index
Question 2
1. exists
2. in
3. into
4. inside
Answer
in
Question 3
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 1/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Chapter 8
Reason — Dictionaries are indexed by keys and its keys must be
Data Structures - I : Linear Lists
of any immutable type.
Chapter 10
Computer Networks - I
Question 4
Chapter 11
Computer Networks - II Following set of commands is executed in shell, what will be the
Chapter 12 output?
Relational Databases
Chapter 13
>>>str = "hello"
Simple Queries in SQL
>>>str[:2]
>>>
1. he
2. lo
3. olleh
4. hello
Answer
he
Question 5
1. list
2. dictionary
3. array
4. tuple
Answer
list
Question 6
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 2/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
1. list
2. dictionary
3. array
4. tuple
Answer
tuple
Question 7
To store values in terms of key and value, what core data type
does Python provide ?
1. list
2. tuple
3. class
4. dictionary
Answer
dictionary
Question 8
1. (6.0, 27.0)
2. (6.0, 9.00)
3. (6, 27)
4. [6.0, 27.0]
5. [6, 27]
Answer
(6.0, 27.0)
Question 9
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 3/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
1. del AL[2]
2. AL[2:3] = []
3. AL[2:2] = []
4. AL[2] = []
5. AL.remove(3)
Answer
del AL[2]
AL[2:3] = []
AL.remove(3)
Question 10
1. This is a string
2. 'This is a string'
3. (This is a string)
4. "This is a string"
Answer
'This is a string'
"This is a string"
Question 11
String1 = "my"
String2 = "work"
print(String1 + String2)
1. my work
2. work
3. mywork
4. my
Answer
Output
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 4/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
mywork
Question 12
String1 = "my"
String2 = "work"
print(String1+String2.upper())
1. mywork
2. MY Work
3. myWORK
4. My Work
Answer
Output
myWORK
Question 13
1. "one" + 'two'
2. 1 + 2
3. "one" + "2"
4. '1' + 2
Answer
'1' + 2
Question 14
1. "7"
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 5/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
2. "34"
3. 34
4. 24
Answer
Output
34
int("3" + "4")
= int("34")
= 34
Question 15
1. Line 3
2. Line 2
3. Line 4
4. Line 1
Answer
Line 4
Question 16
Answer
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 6/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 17
1. dictionary
2. string
3. tuple
4. list
Answer
list
Question 18
1. print(T[1])
2. T[2] = -29
3. print(max(T))
4. print(len(T))
Answer
T[2] = -29
Question 1
Question 2
Question 3
Question 4
Question 5
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 7/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 6
Question 7
Question 8
Question 9
Question 10
Question 11
Question 12
Question 13
Question 14
The values() function returns all values from Key : value pair of a
dictionary.
Question 15
The items() function returns all the Key : value pairs as (key,
value) sequences.
True/False Questions
Question 1
Answer
False
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 8/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 2
Answer
False
Reason — A list can store any data types and even list can contain
another list as element.
Question 3
Answer
True
Question 4
Answer
False
Question 5
Answer
True
Question 6
Answer
True
Question 7
Answer
False
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 9/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 8
The clear( ) removes all the elements of a dictionary but does not
delete the empty dictionary.
Answer
True
Question 9
The max( ) and min( ) when used with tuples, can work if elements
of the tuple are all of the same type.
Answer
True
Question 10
Answer
False
Question 11
For any index n, s[:n] + s[n:] will give you original string s.
Answer
True
Answer
False
Question 1
Answer
(a)
Both Assertion and Reason are true and Reason is the correct
explanation of Assertion.
Explanation
Lists and tuples are similar sequence types in python, but they are
distinct data types. Both are used to store collections of items, but
they have different properties and use cases. Lists are mutable,
meaning you can add, remove, or modify elements after the list is
created. Tuples, on the other hand, are immutable, meaning once
a tuple is created, its contents cannot be changed.
Question 2
Reason. Strings store characters while lists can store any type of
data.
Answer
(b)
Both Assertion and Reason are true but Reason is not the correct
explanation of Assertion.
Explanation
In Python, strings are immutable, meaning once they are created,
their contents cannot be changed. Whenever we modify a string,
python creates a new string object to hold the modified contents,
leaving the original string unchanged. On the other hand, lists in
python are mutable, meaning we can modify their contents after
they have been created. When we modify a list, python does not
create a new list object. Instead, it modifies the existing list object
in place. Strings are sequences of characters, and each character
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 11/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 3
Reason. Strings are immutable types while lists are mutable types
of python.
Answer
(a)
Both Assertion and Reason are true and Reason is the correct
explanation of Assertion.
Explanation
In Python, strings are immutable, meaning once they are created,
their contents cannot be changed. Whenever we modify a string,
python creates a new string object to hold the modified contents,
leaving the original string unchanged. On the other hand, lists in
python are mutable, meaning we can modify their contents after
they have been created. When we modify a list, python does not
create a new list object. Instead, it modifies the existing list object
in place.
Question 4
Answer
(d)
Explanation
Dictionaries are indexed by keys and each key must be immutable
and unique. However, the dictionary itself is mutable, meaning that
we can add, remove, or modify key-value pairs within the
dictionary without changing the identity of the dictionary object
itself. Mutability refers to the ability to change a value in place
without creating a new storage location for the changed value.
Question 5
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 12/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Answer
(a)
Both Assertion and Reason are true and Reason is the correct
explanation of Assertion.
Explanation
A dictionary is a unordered set of key : value pairs and are indexed
by keys. The values of a dictionary can change but keys of
dictionary cannot be changed because through them data is
hashed. Hence dictionaries are mutable but keys are immutable
and unique.
Question 6
Answer
(a)
Both Assertion and Reason are true and Reason is the correct
explanation of Assertion.
Explanation
Insertion sort is a sorting algorithm that builds a sorted list, one
element at a time from the unsorted list by inserting the element at
its correct position in sorted list. In Insertion sort, each successive
element is picked and inserted at an appropriate position in the
previously sorted array.
Type A: Short Answer Questions/Conceptual
Questions
Question 1
Answer
Question 2
Answer
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 13/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Output
Enter name:python
py
th
on
Question 3
Answer
Question 4
Answer
Question 5
Start with the list [8, 9, 10]. Do the following using list functions:
Answer
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 14/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
1. listA[1] = 17
2. listA.extend([4, 5, 6])
3. listA.pop(0)
4. listA.sort()
5. listA = listA * 2
6. listA.insert(3, 25)
Question 6
Answer
Question 7
What are the two ways to add something to a list ? How are they
different ?
Answer
Difference
Example
append method:
extend method:
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 15/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
t1.extend(t2)
print(t1)
Question 8
What are the two ways to remove something from a list? How are
they different ?
Answer
Difference
The difference between the pop() and del is that pop() method is
used to remove single item from the list, not list slices whereas del
statement is used to remove an individual item, or to remove all
items identified by a slice.
Example
pop() method:
Output — 'k'
del statement:
lst = [1, 2, 3, 4, 5]
del lst[2:4]
print(lst)
Output — [1, 2, 5]
Question 9
Answer
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 16/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
List Tuple
Question 10
Answer
1. states = []
2. states.append('Delhi')
3. states.append('Punjab')
4. states2 = ['Rajasthan', 'Gujarat', 'Kerala']
5. states2.insert(0,'Odisha')
6. states2.insert(2,'Tripura')
7. a = states2.index('Gujarat')
states2.insert(a - 1,'Haryana')
8. b = states2.pop(4)
print(b)
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 17/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 11
Answer
Question 12
If a is (1, 2, 3)
Answer
1. a * 3 ⇒ (1, 2, 3, 1, 2, 3, 1, 2, 3)
(a, a, a) ⇒ ((1, 2, 3), (1, 2, 3), (1, 2, 3))
So, a * 3 repeats the elements of the tuple whereas (a, a, a)
creates nested tuple.
2. Yes, both a * 3 and a + a + a will result in (1, 2, 3, 1, 2, 3, 1, 2,
3).
3. This colon indicates (:) simple slicing operator. Tuple slicing is
basically used to obtain a range of items.
tuple[Start : Stop] ⇒ returns the portion of the tuple from index
Start to index Stop (excluding element at stop).
a[1:1] ⇒ This will return empty list as a slice from index 1 to
index 0 is an invalid range.
4. Both are creating tuple slice with elements falling between
indexes start and stop.
a[1:2] ⇒ (2,)
It will return elements from index 1 to index 2 (excluding
element at 2).
a[1:1] ⇒ ()
a[1:1] specifies an invalid range as start and stop indexes are
the same. Hence, it will return an empty list.
Question 13
Answer
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 18/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 14
Answer
Question 15
Answer
Question 16
Answer
1. a Python string
2. a number
3. a tuple (containing only immutable entries)
Question 17
Though tuples are immutable type, yet they cannot always be used
as keys in a dictionary. What is the condition to use tuples as a key
in a dictionary ?
Answer
Question 18
Answer
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 19/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
d = { 1 : 1 }
d[2] = 2
print(d)
d[1] = 3
print(d)
d[3] = 2
print(d)
del d[2]
print(d)
Output
{1: 1, 2: 2}
{1: 3, 2: 2}
{1: 3, 2: 2, 3: 2}
{1: 3, 3: 2}
Explanation
Question 19
Answer
For example:
Output
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 20/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
{1:'a'}
NameError: name 'd' is not defined.
Question 20
Create a dictionary named D with three entries, for keys 'a', 'b' and
'c'. What happens if you try to index a nonexistent key (D['d']) ?
What does python do if you try to assign to a nonexistent key d.
(e.g., D['d'] = 'spam') ?
Answer
1. In this example, the dictionary D does not contain the key 'd'.
Therefore, attempting to access this key by D['d'] results in a
KeyError because the key does not exist in the dictionary.
2. If we try to assign a value to a nonexistent key in a dictionary,
python will create that key-value pair in the dictionary. In this
example, the key 'd' did not previously exist in the dictionary
D. When we attempted to assign the value 'spam' to the key
'd', python created a new key-value pair 'd': 'spam' in the
dictionary D.
Output
Question 21
Answer
1. Bubble Sort
2. Insertion Sort
3. Selection Sort
4. Heap Sort
5. Quick Sort
Question 22
Answer
Bubble Sort :
In Bubble sort, the adjoining values are compared and exchanged
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 21/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
if they are not in proper order. This process is repeated until the
entire array is sorted.
Insertion Sort :
Insertion sort is a sorting algorithm that builds a sorted list one
element at a time from the unsorted list by inserting the element at
its correct position in sorted list.
Type B: Application Based Questions
Question 1(a)
y = str(123)
x = "hello" \* 3
print(x, y)
x = "hello" + "world"
y = len(x)
print(y, x)
Answer
Output
hellohellohello 123
10 helloworld
Explanation
Question 1(b)
x = "hello" + \
"to Python" + \
"world"
for char in x :
y = char
print(y, ':', end=" ")
Answer
Output
h : e : l : l : o : t : o : : P : y : t : h : o : n : w : o
Explanation
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 22/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 1(c)
x = "hello world"
print(x[:2], x[:-2], x[-2:])
print(x[6], x[2:4])
print(x[2:-3], x[-4:-2])
Answer
Output
he hello wor ld
w ll
llo wo or
Explanation
print(x[6], x[2:4]) —
print(x[2:-3], x[-4:-2]) —
Question 2
Write a short Python code segment that adds up the lengths of all
the words in a list and then prints the average (mean) length.
Answer
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 23/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Output
Explanation
1. The code prompts the user to enter a list of words and assigns
it to the variable word_list .
Question 3
a = [1, 2, 3, 4, 5]
print(a[3:0:-1])
Answer
Output
[4, 3, 2]
Explanation
goes up to index 1.
step is -1, indicating that we want to step backward through
the list.
Putting it together:
a[3:0:-1]
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 24/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
[4, 3, 2]
Question 4(a)
arr = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
arr[i - 1] = arr[i]
for i in range(0, 6):
print(arr[i], end = "")
Answer
Output
234566
Explanation
2. for loop iterates over the indices from 1 to 5. For each index
i , it assigns the value of arr[i] to arr[i - 1] , effectively
shifting each element one position to the left. After this loop,
the list arr becomes [2, 3, 4, 5, 6, 6] .
3. Second for loop iterates over the indices from 0 to 5 and prints
each element of the list arr without newline characters
because of end="" parameter. Then it prints the elements of
the modified list arr , resulting in 234566 .
Question 4(b)
Answer
Output
1 #
1 # 2 #
1 # 2 # 3 #
Explanation
2. The outer for loop iterates over each element in the list
Numbers .
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 25/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
3. The inner loop iterates over the range from 1 to the remainder
of Num divided by 8. For example, if Num is 9, the range will
be from 1 to 1 (9 % 8 = 1). If Num is 18, the range will be from
1 to 2 (18 % 8 = 2), and so on. Then it prints the value of N,
followed by a "#", and ensures that the output is printed on the
same line by setting end=" ".
4. After both loops, it prints an empty line, effectively adding a
newline character to the output.
Question 5(a)
Answer
Question 5(b)
Answer
There are no errors in this python code. Lists in python can contain
elements of any type. As lists are mutable so t[0] = 6 is also
valid.
Question 5(c)
Answer
Question 5(d)
t = 'hello'
t[0] = "H"
Answer
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 26/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 5(e)
Answer
Question 6
Answer
Question 7
(a, b, c, d) = ntpl
print("a is:", a)
print("b is:", b)
print("c is:", c)
print("d is:", d)
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 27/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
ntpl = (a, b, c, d)
print(ntpl[0][0] + ntpl[1][1], ntpl[1])
Answer
Output
a is: Hello
b is: Nita
c is: How's
d is: life ?
Hi Nita
Explanation
ntpl[0] ⇒ "Hello"
∴ ntpl[0][0] ⇒ "H"
ntpl[1] ⇒ "Nita"
∴ ntpl[1][1] ⇒"i"
Question 8
Answer
Output
True
Explanation
Question 9
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 28/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
1. True
2. False
3. 1
4. Exception
Answer
Output
True
Explanation
In the given python code snippet, id1 and id2 will point to two
different objects in memory as del rec deleted the original
dictionary whose id is stored in id1 and created a new dictionary
with the same contents storing its id in id2 . However, id1 == id2
will compare the contents of the two dictionaries pointed to by id1
and id2 . As contents of both the dictionaries are same hence it
returns True . If in this code we add another line print(id1 is
id2) then this line will print False as id1 and id2 point to two
Question 10
Answer
Output
Explanation
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 29/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 11
Answer
def display(my_list):
for item in my_list:
if item.isdigit():
print(item * 3)
else:
print(item + '#')
display(my_list = eval(input("Enter the list :")))
Output
Explanation
1. The code prompts the user to enter the elements of the list
separated by spaces and stores the input as a single string in
the variable my_list .
2. Then splits the input string my_list into individual elements and
stores them in a new list called new_list .
Question 12
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 30/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Answer
Question 13
my_dict = {}
my_dict[(1,2,4)] = 8
my_dict[(4,2,1)] = 10
my_dict[(1,2)] = 12
sum = 0
for k in my_dict:
sum += my_dict[k]
print(sum)
print(my_dict)
Answer
Output
30
{(1, 2, 4): 8, (4, 2, 1): 10, (1, 2): 12}
Explanation
Question 1
Solution
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 31/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
if length == 12 \
and phNo[3] == "-" \
and phNo[7] == "-" \
and phNo[:3].isdigit() \
and phNo[4:7].isdigit() \
and phNo[8:].isdigit() :
print("Valid Phone Number")
else :
print("Invalid Phone Number")
Output
=====================================
Question 2
Number of words
Number of characters (including white-space and punctuation)
Percentage of characters that are alpha numeric
Hints
Solution
for ch in str :
if ch.isspace() :
spaceCount += 1
elif ch.isalnum() :
alnumCount += 1
print("Original Sentences:")
print(str)
Output
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 32/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Python was conceived in the late 1980s by Guido van Rossum at
Number of words = 34
Number of characters = 205
Alphanumeric Percentage = 80.48780487804879
Question 3
Write
a program that takes any two lists L and M of the same size
and adds their elements together to form a new list N whose
elements are sums of the corresponding elements in L and M. For
instance, if L = [3, 1, 4] and M = [1, 5, 9], then N should equal [4, 6,
13].
Solution
for i in range(len(L)):
N.append(L[i] + M[i])
print("List N:")
print(N)
Output
Question 4
Solution
l = l[-1:] + l[:-1]
print("Rotated List")
print(l)
Output
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 33/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 5
Write a short python code segment that prints the longest word in a
list of words.
Solution
Output
Question 6
Write a program that creates a list of all the integers less than 100
that are multiples of 3 or 5.
Solution
a = []
for i in range(0,100):
if (i % 3 == 0) or (i % 5 == 0) :
a.append(i)
print(a)
Output
[0, 3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 30, 33, 35
Question 7
Define two variables first and second so that first = "Jimmy" and
second = "Johny". Write a short python code segment that swaps
the values assigned to these two variables and prints the results.
Solution
first = "Jimmy"
second = "Johny"
temp = first
first = second
second = temp
print("first =", first)
print("second =", second)
Output
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 34/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
first = Johny
second = Jimmy
Question 8
Solution
lst = [0,1]
a = 0
b = 1
c = 0
for i in range(7):
c = a + b
a = b
b = c
lst.append(c)
tup = tuple(lst)
Output
Question 9
(a) Ask the user to enter a month name and use the dictionary to
tell them how many days are in the month.
(d) Print out the (key-value) pairs sorted by the number of days in
each month.
Solution
days_in_months = {
"january":31,
"february":28,
"march":31,
"april":30,
"may":31,
"june":30,
"july":31,
"august":31,
"september":30,
"october":31,
"november":30,
"december":31
}
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 35/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
m = input("Enter name of month: ")
if m not in days_in_months:
print("Please enter the correct month")
else:
print("There are", days_in_months[m], "days in", m)
day_month_lst = []
for i in days_in_months:
day_month_lst.append([days_in_months[i], i])
day_month_lst.sort()
month_day_lst =[]
for i in day_month_lst:
month_day_lst.append([i[1], i[0]])
sorted_days_in_months = dict(month_day_lst)
print()
print("Months sorted by days:", sorted_days_in_months)
Output
Question 10
Solution
Output
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 36/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Question 11
Solution
Output
Question 12
Solution
Output
Prev Next
Python Revision Tour Working with Functions
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 37/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Class - 6 Concise Biology Selina Solutions Class - 9 ICSE Mathematics Sample Paper Tests Pricing
Class - 6 Veena Bhargava Geography Solutions Class - 9 ICSE Biology Practice Tests About Us
Class - 6 Effective History & Civics Solutions Class - 10 ICSE Mathematics Practice Tests Contact Us
Class - 7 Concise Physics Selina Solutions Class - 10 ICSE Mathematics Sample Paper Tests Privacy Policy
Class - 7 Concise Chemistry Selina Solutions Class - 10 ICSE Biology Sample Paper Tests Terms of Service
Class - 7 Dalal Simplified Middle School Chemistry Solutions Class - 10 ICSE Computer Applications Sample Paper Tests
Class - 7 Concise Biology Selina Solutions Class - 12 CBSE Computer Science Practice Tests
Class - 7 Living Science Biology Ratna Sagar Solutions Class - 12 CBSE Computer Science Sample Paper Tests
Class - 7 Around the World Geography Solutions Class - 12 CBSE Informatics Practices Sample Paper Tests
Class - 8 Concise Chemistry Selina Solutions Java Number Programs (ICSE Classes 9 / 10)
Class - 8 Dalal Simplified Middle School Chemistry Solutions Java Number Programs (ISC Classes 11 / 12)
Class - 8 Concise Biology Selina Solutions Output Questions for Class 10 ICSE Computer Applications
Class - 8 Living Science Biology Ratna Sagar Solutions Algorithms & Flowcharts for ICSE Computers
Class - 8 Around the World Geography Solutions ICSE Class 8 Computers Differentiate Between the Following
Class - 8 Veena Bhargava Geography Solutions CBSE Class 12 Computer Science Important Output Questions
Class - 8 Effective History & Civics Solutions CBSE Class 12 Computer Science Assertion Reason Questions
Class - 8 Kips Logix Computers Solutions CBSE Class 12 Computer Science File Handling Questions
Class - 9 Dalal Simplified ICSE Chemistry Solutions Class - 9 NCERT Mathematics Solutions
Class - 9 Total Geography Morning Star Solutions Class - 9 NCERT Geography Contemporary India 1 Solutions
Class - 9 Veena Bhargava Geography Solutions Class - 9 NCERT History India & Contemporary World 1 Solutions
Class - 9 Total History & Civics Solutions Class - 9 Sumita Arora Computer Code 165 Solutions
Class - 9 Kips Logix Computers Solutions Class - 9 Kips Cyber Beans Computer Code 165 Solutions
Class - 10 Dalal Simplified ICSE Chemistry Solutions Class - 10 NCERT Geography Contemporary India 2 Solutions
Class - 10 Concise Biology Selina Solutions Class - 10 NCERT History India & Contemporary World 2 Solutions
Class - 10 Total Geography Morning Star Solutions Class - 10 NCERT Democratic Politics 2 (Civics) Solutions
Class - 10 Veena Bhargava Geography Solutions Class - 10 NCERT Economic Development Solutions
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 38/39
3/20/25, 5:23 AM Chapter 2: Python Revision Tour II | Solutions of Computer Science with Python by Sumita Arora for Class 12 CBSE & NCERT …
Class - 10 Total History & Civics Solutions Class - 10 Sumita Arora Computer Code 165 Solutions
Class - 10 Sumita Arora ICSE Computers Solutions Class - 10 Kips Cyber Beans Computer Code 165 Solutions
Class - 10 Kips Logix Computers Solutions Class - 11 CBSE Sumita Arora Python Solutions
ICSE/ISC SOLVED QUESTION PAPERS
Class - 11 CBSE Preeti Arora Python Solutions
Class - 10 ICSE Maths Solved Competency Focused Questions
Class - 11 CBSE Informatics Practices Preeti Arora Solutions
Class - 10 ICSE Biology Solved Competency Focused Questions
Class - 12 CBSE Sumita Arora Python Solutions
ICSE Class 10 Computers Solved 10 Yrs Question Papers
Class - 12 CBSE Preeti Arora Python Solutions
Sample Papers ICSE Class 10 Computer Applications
Class - 12 NCERT Computer Science Solutions
ICSE Class 10 Physics Solved 10 Yrs Question Papers
Class - 12 CBSE Informatics Practices Sumita Arora Solutions
Sample Papers ICSE Class 10 Physics
Class - 12 CBSE Informatics Practices Preeti Arora Solutions
ICSE Class 10 Chemistry Solved 10 Yrs Question Papers
https://www.knowledgeboat.com/learn/sumita-arora-python-computer-science-class-12-cbse/solutions/BevZLk/revision-tour-2 39/39