Page 312 - Computer Science Class 11 Without Functions
P. 312
7. Consider the following assignment statement :
lst = list('Term 1 Exam')
Match the following statement with the outputs that will be produced when they are executed.
1. print(lst[1:12:3]) a. []
2. print(lst[:-8]) b. ['e', ' ', 'E', 'm']
3. print(lst[-6:0]) c. ['x', 'E', ' ', '1', ' ']
4. print(lst[-3:-8:-1]) d. ['T', 'e', 'r']
5. print(lst[:24:3]) e. ['T', 'm', ' ', 'a']
Ans: 1-b , 2- d, 3- a, 4-c 5 e
8. Give all possible outputs that would print the name of at least one continent when the following code is executed.
import random # Pyth on module to generate random numbers
continents = ['Asia', 'Australia', 'South America', 'North America', 'Europe', 'Antarctica']
lower = random.randint(2, 4) # randint yields random numbers between a given range
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#
9. What will be the output produced on the 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', '', '')
10. Will the following code execute successfully? If yes, what will be the output produced on the execution of the code? If not,
what is the error in the code?
myList = [1, 0, -1]
newList = myList * 3
newList.insert(-1, 5)
value = newList.index(4)
print(value)
Ans: No, the code will not execute successfully as 4 is not present in the list newList, so index() will result in an error.
11. What will be the output produced on the execution of the following code?
data =['WHAT', 1, 'IS', 2, 'THIS', 3, 'PLEASE', 4]
alpha = ''
beta = 0
for c in range(1, 7, 2):
beta = beta + c
310 Touchpad Computer Science-XI

