Page 202 - Information_Practice_Fliipbook_Class11
P. 202
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.
8. What will be the output produced on 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
alpha = alpha + data[c-1] + '!!'
beta = beta + data[c]
print(alpha, beta, sep='#')
Ans. WHAT!!IS!!THIS!!#15
Assertion and Reasoning Based Questions
The following questions are assertion(A) and reasoning(R) based. Mark the correct choice as
a. Both A and R are true and R is the correct explanation of A
b. Both A and R are true and R is not the correct explanation of A
c. A is true but R is false
d. A is false but R is true
1. Assertion(A): A list assignment does not create a new copy of the list.
Reasoning (R): List is a mutable data type.
2. Assertion(A): The method extend() can insert elements at any position in the list.
Reasoning(R): extend() only takes an iterable sequence as an argument.
Ans. 1. a 2. d
Case-based Questions
1. Shamitabh's teacher wants him to store the ages of all his friends in the form of a list and then perform the following
operations:
● Display the average age of all his friends
● Display the count of all his friends
● Display the most frequently occurring age value in the list
Help Shamitabh to do his assignment using the Python functionality.
Ans: To develop the desired program to summarize the list of age, Shamitabh needs to take the following approach:
Approach:
a. Prompt the user to enter age one by one and append to an initially empty list.
b. If the user reponds by y or Y, continue, else stop and process data.
c. Use mean and mode methods of statistics module.
import statistics
'''
Objective: To read numbers representing ages and mean, count, and mode of all ages.
Input: a list of age
188 Touchpad Informatics Practices-XI

