0% found this document useful (0 votes)
7 views5 pages

Revision WS-Tuples & Dictionary

This document is a revision worksheet for Grade XI Computer Science focusing on tuples and dictionaries in Python. It includes multiple-choice questions (MCQs) and programming tasks related to the concepts of tuples and dictionaries, such as their properties, methods, and how to manipulate them. The worksheet aims to test students' understanding and application of these data structures.
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)
7 views5 pages

Revision WS-Tuples & Dictionary

This document is a revision worksheet for Grade XI Computer Science focusing on tuples and dictionaries in Python. It includes multiple-choice questions (MCQs) and programming tasks related to the concepts of tuples and dictionaries, such as their properties, methods, and how to manipulate them. The worksheet aims to test students' understanding and application of these data structures.
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/ 5

Grade XI

Sub: Computer Science


Revision Worksheet – 3
Ch-Tuples & Dictionaries

I. MCQ
1. Which of the following is a Python
tuple? a) [1, 2, 3].
b) (1, 2, 3)
c) {1, 2,
3} d) {}
2. Suppose t = (1, 2, 4, 3), which of the following is
incorrect? a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))
3. What will be the output?
>>>t=(1,2,4,3)
>>>t[1:3]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
4. What will be the output?
>>>t=(1,2,4,3)
>>>t[1:-1]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
5. What will be the output?
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0,
len(t), 2)] a) [2, 3, 9].
b) [1, 2, 4, 3, 8, 9].
c) [1, 4, 8].
d) (1, 4, 8)
6. What will be the
output? d =
{"john":40,
"peter":45} d["john"]
a) 40
b) 45
c) “john”
d) “peter”
7. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john”
what command do we use
a) d.delete(“john”:40)
b) d.delete(“john”)
c) del d[“john”].
d) del d(“john”:40)
8. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries
in dictionary which command do we use?
a) d.size()
b) len(d)
c) size(d)
d) d.len()
9. What will be the
output? d =
{"john":40,
"peter":45}
print(list(d.keys()))
a) [“john”, “peter”].
b) [“john”:40, “peter”:45].
c) (“john”, “peter”)
d) (“john”:40, “peter”:45)
10.Suppose d = {“john”:40, “peter”:45}, what happens when we try to
retrieve a value using the expression d[“susan”]?
a) Since “susan” is not a value in the set, Python raises a KeyError
exception b) It is executed fine and no exception is raised, and it
returns None
c) Since “susan” is not a key in the set, Python raises a KeyError
exception d) Since “susan” is not a key in the set, Python raises a
syntax error
11. Which of these about a dictionary is false?
a) The values of a dictionary can be accessed using
keys b) The keys of a dictionary can be accessed
using values c) Dictionaries aren’t ordered
d) Dictionaries are mutable
12. Which of the following is not a declaration of the
dictionary? a) {1: ‘A’, 2: ‘B’}
b) dict([[1,”A”],
[2,”B”]]) c)
{1,”A”,2”B”}
d) {}

II. Answer the following Questions


1. What is a dictionary? give example

2. Write a python script to traverse a dictionary

3. Explain 5 list built in methods of dictionary

4. What is key value pair? Explain


5. Write a Python script to sort (ascending and descending) a dictionary
by value.

6. Write a Python script to add a key to a dictionary.


7. Sample Dictionary : {0: 10, 1:
20} Expected Result : {0: 10, 1:
20, 2: 30}

8. Write a Python script to concatenate following dictionaries to create a


new one.

9. Sample
Dictionary :
dic1={1:10,
2:20}
dic2={3:30,
4:40}
dic3={5:50,6:60
}
Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}

10. Write a Python script to check if a given key already exists in

a dictionary. 11.Write a Python program to iterate over dictionaries

using for loops.

12. Write a Python script to generate and print a dictionary that


contains a number (between 1 and n) in the form (x, x*x).

13. Sample Dictionary ( n = 5) :


Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

14. Write a Python script to print a dictionary where the keys are
numbers between 1 and 15 (both included) and the values are square
of keys.

15. Sample Dictionary


{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11:
121, 12: 144,
13: 169, 14: 196, 15: 225}

16. Write a Python script to merge two Python

dictionaries. 17.What is the Difference between a

tuple and a dictionary ? 18.What is an empty tuple?

19. Write a Python program to convert a tuple to a string.

20. Write a Python program to get the 4th element and 4th element
from last of a tuple.

21. Write a Python program to find the repeated items of a tuple.


22. Write a Python program to check whether an element exists within a
tuple.

You might also like