0% found this document useful (0 votes)
67 views4 pages

Chap 10 - Worksheet

grade-11 chapter10 worksheet

Uploaded by

arthyr
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)
67 views4 pages

Chap 10 - Worksheet

grade-11 chapter10 worksheet

Uploaded by

arthyr
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/ 4

Computer Science worksheet - 2024 -25

Grade: XI Sec: B, C D & E


Chapter 10 – Tuple & Dictionary
1) The record of 5 students (SNo and Name) are stored in the following dictionary: D1 =
{1:’Tanay’,2 :’Ram’, 3:’Shubha’, 4:’Sudhanshu’, 5:’Rahul’} Write the statement to retrieve
the following information:
(a) All SNo.s and Names of the students.
(b) Total number of pairs of SNo and Name.
(c) Check the entered SNo is present or not.
(d) Delete the data of SNo 4.

2) Suppose T is a tuple . Which of the following statement(s) would give an error after
executing the following code ?
T = (100,101,-89,45)
print(sum(T)) #Statement 1
print(T.sort()) #Statement 2
x, y, z, w = T #Statement 3
print(sorted(T)) #Statement 4
(a) Statement 1 (b) Statement 2 (c) Statement 3 (d) Statement 4

3) Which of the following will delete the key_value pair for key = "tiger" in dictionary ?
di = {"loin" :"wild", "tiger" : "wild", "cat" : "domestic" , "dog" : "domestic"}
(a) del di["tiger"] b) delete(d1["tiger" : "wild"])
(c) delete(di.["tiger"]) (d) del(di.["tiger])

4) (a) Predict the output of the Python code given below:


a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])
(b) Write a program using dictionary to count the frequency of each character in a given
string .Example :If the string is given as :” i like python programming”
OUTPUT :
{'i': 3, ' ': 3, 'l': 1, 'k': 1, 'e': 1, 'p': 2, 'y': 1, 't': 1, 'h': 1, 'o': 2, 'n': 2, 'r': 2, 'g': 2, 'a': 1,
'm': 2}
5) (a) Write the use of popitem() in dictionary .
(b) Write a Python Program to input name , department and salary of 3 employees from
the user and store them in a dictionary . Display all the employee names , departments and
salaries separately .
6) Write a program to create a third dictionary from two dictionaries having some common
keys , in way so that the values of common keys are added in the third dictionary .
Example :
If two dictionaries are as follows :
dct1 = {1 : 100 , 2 : 200 , 3 : 300}
dct2 = {1 : 300 , 2 : 200 , 5 : 400}
OUTPUT :
The resultant dictionary : {1: 400, 2: 400, 3: 300, 5: 400}

7) Find the output of the following:


T1=(10,20,30,40,50)
T2=(100,200,300)
T1,T2=T2,T1
print(min(T1))
print(max(T2))

8) Find the error. Following code intends to create a tuple with three identical strings. But
even after successfully executing following code(No error reported by python), The len()
returns a value different from 3. Why?
tup1=(‘Mega’)*3
print(len(tup1))
9) WAP that creates a tuple storing first 9 terms of Fibonacci series.
10) When would sum() not work for tuples?
11) Do min() & max() always work for tuples?
12) Is the working of in operator and tuple.index() same?
13) What is the output of the following?
S=0
d1={“cat”:12,’dog’: 6, ‘elephant’:23,’bear’:20}
for a in d1:
if len(a)>3:
s=s+d1[a]
print(s)
14) WAP to check if a dictionary is empty.
15) WAP to find the highest 2 values in a dictionary.
16) WAP to create a dictionary from a string
17) Discuss the working of copy() if (i) the values are of immutable types, (ii) the values are
of mutable types.
18) How is pop() different from popitem()?
19) Can you use sum() for calculating the sum of values of a dictionary?
20) Why is a dictionary termed as an unordered collection of objects?

21) Write a Program in Python to create a dictionary with names of employees, their salary
and access them.
Output format:
Enter employee name : Amit
Enter employee salary : 20000
Do you want to add more employee details(y/n) :y
Enter employee name : Sachin
Enter employee salary : 25000
Do you want to add more employee details(y/n) :y
Enter employee name : Saanvi
Enter employee salary : 28000
Do you want to add more employee details(y/n) :n
{'Amit': 20000, 'Sachin': 25000, 'Saanvi': 28000}

22. Write a program in python, to input a dictionary Emp which contains eid and ename
as key value pair and displays the name in uppercase of the values whose names are longer
than 5
characters.
For example:
Emp = {101: 'Rahul', 102: 'Hardik', 103: 'Virat', 104:'Jaspreet'}
The output should be:
HARDIK
JASPREET

23. Write a Python program to reverse a tuple.


24. Write a Python program to convert a given string list to a tuple.

25. Write a Python program to calculate the product, multiplying all the numbers in a given
tuple.
Original Tuple:
(4, 3, 2, 2, -1, 18)
Product - multiplying all the numbers of the said tuple: -864
Original Tuple:
(2, 4, 8, 8, 3, 2, 9)
Product - multiplying all the numbers of the said tuple: 27648

26.
1.Write a program in python, to input a dictionary Emp
which contains eid and ename as key value pair and
displays the name in uppercase of the values whose
names are longer than 5 characters.
For example: Emp = {101: 'Rahul', 102: 'Hardik', 103:
'Virat', 104:'Jaspreet'}
The output should be:
HARDIK
JASPREET
2. Write a Python program to reverse a tuple.
3. Write a Python program to convert a given string into
list ,and the list into a tuple.
4. Write a Python program to calculate the product,
multiplying all the numbers in a given tuple.
Original Tuple:
(4, 3, 2, 2, -1, 18)
Product - multiplying all the numbers of the said tuple:
-864
Original Tuple:
(2, 4, 8, 8, 3, 2, 9)
Product - multiplying all the even numbers of the said
tuple: 1024

You might also like