Page 360 - Computer Science Class 11 With Functions
P. 360
Match the following statement with the outputs that will be produced when they are executed.
a. print(lst[1:12:3]) i. []
b. print(lst[:-8]) ii. ['e', ' ', 'E', 'm']
c. print(lst[-6:0]) iii. ['x', 'E', ' ', '1', ' ']
d. print(lst[-3:-8:-1]) iv. ['T', 'e', 'r']
e. print(lst[:24:3]) v. ['T', 'm', ' ', 'a']
Ans. a-ii, b-iv, c-i, d-iii, e-v
8. What will be the output produced on execution of the following code?
def search(myList, y = 5):
count = 1
for x in myList:
if abs(x) == y:
count += 1
return count
lst = [4, 7, -3, 5, -5, 6, 10]
searchKey = 20
print('List to be searched:', lst)
keyCount = search(lst, searchKey)
print('Number of occurrences of', searchKey, 'is: ', keyCount)
keyCount = search(lst)
print('Number of occurrences of default key 5 is: ', keyCount)
Ans. List to be searched: [4, 7, -3, 5, -5, 6, 10]
Number of occurrences of 20 is: 1
Number of occurrences of default key 5 is: 3
9. Give all possible outputs that would print the name of at least one continent when the following code is executed.
import random
continents = ['Asia', 'Australia', 'South America', 'North America', 'Europe', 'Antarctica']
lower = random.randint(2, 4)
upper = random.randint(3, 5)
for x in range(lower, upper):
print(continents[x], end = '#')
Ans. South America#
South America#North America#
South America#North America#Europe#
North America#
North America#Europe#
Europe#
10. What will be the output produced on execution of the following code?
myString = 'God helps those who help themselves'
print(myString.split())
print(myString.split('my'))
print(myString.partition('my'))
Ans. ['God', 'helps', 'those', 'who', 'help', 'themselves']
['God helps those who help themselves']
('God helps those who help themselves', '', '')
358 Touchpad Computer Science-XI

