0% found this document useful (0 votes)
106 views7 pages

11 - CS - 4WT Revision

The document contains a practice test for class 11 with 20 multiple choice questions covering topics like tuples, lists, dictionaries in Python. Some questions ask students to write Python code to perform tasks like finding the largest element in a list, reversing a list, creating a dictionary from roll numbers and marks etc. Students are tested on their understanding of built-in functions for lists and tuples as well as basic syntax and applications of various Python data structures.

Uploaded by

Priyansh Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views7 pages

11 - CS - 4WT Revision

The document contains a practice test for class 11 with 20 multiple choice questions covering topics like tuples, lists, dictionaries in Python. Some questions ask students to write Python code to perform tasks like finding the largest element in a list, reversing a list, creating a dictionary from roll numbers and marks etc. Students are tested on their understanding of built-in functions for lists and tuples as well as basic syntax and applications of various Python data structures.

Uploaded by

Priyansh Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

MILESTONE ACADEMY

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?

>>> tuple1 = (5)    #statement 1


>>> len(tuple1)     #statement 2

Q.5Differentiate between append() and extend() function.


Q.6 To get all the keys of a dictionary, ___________- method is used
Q.7 How are dictionaries different from list.
Q.8Elements in a tuple can be of_______ type.

Q.9 Tuples can be used as keys in Python dictionary. True or False?


Q10. What will be the output of the following code segment:

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)

Q11. Discuss the utility and significance of Lists in Python, briefly.

Q12. What’s the purpose of the del operator and pop method?

Q13 . What are list slices?

Q14. Write a program that reverses a list of integers (in place).

Q15. Differentiate between append() and extend() functions of list.

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.

(iv)Roll no. of the student.


(v) Change the name of the student from ‘Raman ‘ to ‘Raghav’.
Q.24 WAP to read roll number and marks of four students and create a dictionary from it having roll numbers as
keys.
Q.25.Consider the following dictionary stateCapital:
stateCapital={“AndhraPradesh”:”Hyderabad”,”Bihar”:”patina”,”Maharashtra”:”Mumbai”,
”Rajasthan”:”Jaipur”}
Find the optput of the following statements:
(i) print(stateCapital.get(“Bihar”))
(ii) print(stateCapital.keys())
(iii) print(stateCapital.values())
(iv) print(stateCapital.items())
(v) print(len(stateCapital))
Q30. The record of a student (Name, Roll No., Marks in five subjects and percentage of marks) is
stored in the following list:

stRecord = [ ‘Raman’, ‘A-36’ , [56, 98, 99, 72, 69], 78.8 ]

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. Set the second entry (index 1) to 17


2. Add 4, 5 and 6 to the end of the list
3. Remove the first entry from the list
4. Sort the list
Q33.What does each of the following expressions evaluate to? Suppose that L is the list
["These", ["are", "a", "few", "words"], "that", "we", "will", "use"].

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.

Qhat will be the output of the following code segment:

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.

Sol L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 4, 5, 2, 4]


e = int(input("Enter element to count : "))
print("Element ", e, " occurs", L.count(e)," times in List")

OUTPUT :

Enter element to count : 2


Element 2 occurs 3 times in List

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]

Q.Discuss the utility and significance of Lists in Python, briefly.

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's the purpose of the del operator and pop method?

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?

Ans. Advantages of tuples over list are


1. Tuples are faster than list (due to their fixed size)
2. Tuples can be used as keys of dictionary. (due to their immutable nature)
3. Elements of tuples can not be deleted by mistake. ( due to their immutable nature )
Q8. TypeError occurs while statement 2 is running.
Give reason. How can it be corrected?

tuple1 = (5) #statement 1


len(tuple1) #statement 2
Ans. As tuple1 variable is of integer type (you can verify by writing print(type(tuple1))) not of type ‘tuple’ and
len function returns the length of any sequence like list, tuple, string etc. So the statement 2 is returning error.
Q.Write a program to input names of n students and store them in a tuple. Also, input a name from the user
and find if this student is present in the tuple or not.
def searchname(t1,nm):
for a in t1:
if a == nm:
print(nm , " Name is present in Tuple")
return
print("Name not found")
n = int(input("How many names you want to enter : "))
name = ()
for i in range(n):
nm = input("Enter name : ")
name = name + (nm,)
nm = input("Enter name to search : ")
searchname(name, nm)
OUTPUT
How many names you want to enter : 3
Enter name : Amit
Enter name : Anuj
Enter name : Ashish
Enter name to search : Anuj
Anuj Name is present in Tuple
Ans b)
n = int(input("How many names you want to enter : "))
name = ()
for i in range(n):
nm = input("Enter name : ")
name = name + (nm,)
nm = input("Enter name to search : ")
if nm in name:
print(nm," Name is present in Tuple")
else:
print(nm," Name is not present in Tuple")
OUTPUT:
How many names you want to enter : 3
Enter name : Amit
Enter name : Anuj
Enter name : Ashu
Enter name to search : Ashu
Ashu Name is present in Tuple
Q3. Write a Python program to find the highest 2 values in a dictionary.
Ans.
D = {'A' : 23, 'B' : 56, 'C' : 29, 'D' : 42, 'E' : 78 }
val = [ ]
v = D.values()
for i in v:
val.append(i)
val.sort()
print("Two maximum values are")
print(val[-1])
print(val[-2])

You might also like