11 - CS - 4WT Revision
11 - CS - 4WT Revision
CLASS-11
FOURTH WEEKLY TEST
Q.1What is a tuple ?
Q.2 “Lists and Tuples are ordered”. Explain.
Q.3 What advantages do tuples have over lists?
Q.4TypeError occurs while statement 2 is running. Give reason. How can it be corrected?
a) myList = [1,2,3,4,5,6,7,8,9,10]
del myList[::2]
print(myList)
b) list1 = [12,32,65,26,80,10]
list1.sort()
print(list1)
Q12. What’s the purpose of the del operator and pop method?
Q16. Write a function that returns the largest element of the list passed as parameter.
Q.17.Write a python programm that returns the largest element of the list passed as parameter.
Q.18.Write a program to create a dictionary containing names of competition winner students as keys and number of
their wins as values.
Q.19 What will be the output:
tp1=(22,44,33)
tp3=tp1*2
print(tp3)
Q.20What type of error is returned by following code:
a=(“Amit”, “Sumit”,”Ashish”,”Sumanta”)
print(a.index(“Suman”))
a. SyntaxError b. ValueError c. TypeError d. NameErro
Q.21What will be the output of the following Python code?
a={1:"A",2:"B",3:"C
for i in a:
print(i,end=" ")
Q.22.Consider the following tuples,tuples1 and tuples2:
Tuple1=(123,21,445,657,455,59,555,455)
Tuple2=(450,240)
Find the output of the following statements:
(i) print(tuple1.index(45))
(ii) print(tuple1.count(45))
(iii) print(tuple1+tuple2)
(iv) print(len(tuple2))
(v) print(max(tuple1))
Q.23The record of a student (Name, Roll No, Marks in five subjects and percentage of marks) is stored in the
following list:
stReecord=[‘Raman’,’A-36’,[56,98,99,72,69],78.8]
Write Python statement to retrieve the following information from the list stReecord.
(i) Percentage of student
(ii) Marks in the fifth subject
(iii) Maximim marks of the student.
Write Python statements to retrieve the following information from the list stRecord.
a) Percentage of the student
b) Marks in the fifth subject
c) Maximum marks of the student
Q31. Consider a list: list1 = [6, 7, 8, 9]What is the difference between the following operations on
list1:
a. list1 * 2
b. list1 *= 2
Q32.Start with the list [8, 9, 10]. Do the following using list functions:
1. L[1][0::2]
2. "a" in L[1][0]
3. L[:1] + L[1]
4. L[2::2]
5. L[2][2] in L[1]
Q34. Write a program to read a list of n integers (positive as well as negative). Create two new lists,
one having all positive numbers and the other having all negative numbers from the given list.
Print all
three lists.
Q.35Compare lists with strings. How are they similar and how are they different?
Q.36.Write a program rotates the elements of a list so that the element at the first index moves to the second index,
the element in the second index moves to the third index, etc., and the element in the last index moves to the first
index
Q37. Write a program in python which swap the alternate members of list (assuming that even number of elements in
the list). like as shown below:
Original List : L = [23, 45, 67, 29, 12, 1]
After Swaping : L = [45,23, 29, 69, 1, 12]
**********************************************************************************************
**
Q.38Write a program to find the number of times an element occurs in the list.
Q.Write a program to read a list of n integers and find their median.
Note: The median value of a list of values is the middle one when they are arranged in order. If there are two middle
values then take their average.
myList = [1,2,3,4,5,6,7,8,9,10]
for i in range(0, len(myList)):
if i % 2 == 0:
print(myList[i])
Ans.
1
3
5
7
9
Write a program to find the number of times an element occurs in the list.
OUTPUT :
Q.Write a function that returns the largest element of the list passed as parameter.
Ans.
def maxL(a):
return(max(a))
L = [1, 23, 43, 21, 3, 76, 54, 43, 45]
Answer
Python lists are containers that can store an ordered list of values of same or different data types together in a
single variable. The fact that elements of a list need not be homogeneous makes them highly adaptable and
powerful data structure in Python. Lists provide fast access to its elements using index numbers. Python lists
are mutable which makes them memory efficient. They serve as the basic building blocks for programs that
process large amounts of data.
What does each of the following expressions evaluate to? Suppose that L is the list
["These", ["are", "a", "few", "words"], "that", "we", "will", "use"].
6. L[1][0::2]
7. "a" in L[1][0]
8. L[:1] + L[1]
9. L[2::2]
10. L[2][2] in L[1]
Answer
1. ['are', 'few']
2. True
3. ['These', 'are', 'a', 'few', 'words']
4. ['that', 'will']
5. True
Q5. What advantages do tuples have over lists?