Class 11 Free Python Dictionary Assignments

Share with others

Class 11 Python Dictionary Assignments

PYTHON DICTIONARY
Python Dictionary

CHAPTER: PYTHON DICTIONARY

ASSIGNMENT SET – 1

Time: 30 min                                                                                   M.M. – 20

Instructions:

  • All Questions are compulsory
  • Q1 to Q6 carry 1 mark
  • Q7 to Q10 carry 2 marks
  • Q11 to Q12 carry 3 marks

Q1. Keys must be ______ in dictionary.(mutable/immutable)

Q2. Write a built in function which is used to create an empty dictionary.

Q3. Write the code to print only keys of the following dictionary.

        D = {“Amit” : 40, “Sunil” : 34, “Naina” : 30}

Q4. Write the code to add the following detail in dictionary given above.

        “Ravi” – 45

Q5. Write the output of the following code:

       D = {“Amit” : 40, “Sunil” : 34, “Naina” : 30}

       print(D[‘Amit’] + D[‘Sunil’])

Q6. Name the function which is used to return a value of the given key.

Q7. Write two differences between List and Dictionary.

Q8. Write the output of the following:

         m = {1 : “Jan”, 2 : ‘Jun’, 3 : ‘Aug’}

          print(m[1])

         print(m[“jan”])

Q9. Explain keys() function of dictionary with example.

Q10. Write one similarity and one difference between del statement and pop() function in reference to dictionary.

Q11. Find errors in the following statement and write the correct code:

         num = {1 : 10, 2 : 20, 3 : 30, 4 : 40, 5 : 50}

  1. print(num.item())
  2. print(num.len())
  3. print(pop(5))

Q12. Write a program to input details of five employees in a dictionary like employee number, employee name, employee salary and display their details in tabular form.

Enter detail to download in pdf Format


CHAPTER: PYTHON DICTIONARY

ASSIGNMENT SET – 2

Time: 30 min                                                                                   M.M. – 20

Instructions:

  • All Questions are compulsory
  • Q1 to Q6 carry 1 mark
  • Q7 to Q10 carry 2 marks
  • Q11 carry 6 marks
Q1.What do you mean by dictionary in python?1
Ans.A dictionary is an unordered collection of items and each item is a pair of Key and Value.
Q2Which of the following is a dictionary?
1.       L1 = [34, 56, 64, 32]
2.       L2 = (23, 34, 65)
3.       L3 = {1 : 23, 2 : 45}
1
Ans. L3
Q3In dictionary, out key and value which should be unique for all items in dictionary?1
Ans.Key should be unique for all items in dictionary.
Q4.Write two important features of dictionary.1
Ans.Two important features of dictionary are:
1.       Dictionary is mutable.
2.       Keys are always unique while values may not be.
Q5. Write two ways to create a blank dictionary by name d1.1
Ans.Two ways to create blank dictionary are:
1.       d1 = { }
2.       d1 = dict( )
Q6.Write the output of the following.
D = { }
D[1] = “Amit”
D[2] = “Suman”
print(D)
1
Ans. {1: ‘Amit’, 2: ‘Sumit’}
Q7.Write the output of the following in reference to the following dictionary
d={1:”Cricket”, 2 : “Hockey”,3 : “Football”}
 
a.   

for i in d:
  print(i)

b.

for i in d:
  print(d[i])
2
Ans.
a.

1
2
3


b.

Cricket
Hockey
Football
Q8.Write a program to accept roll numbers and name of three students from the user, store the detail in dictionary by taking roll number as key and name as primary key.2
Ans.d={ }
for i in range(3):
  rn=int(input(“Enter roll number”))
  nm=input(“Enter Name”)
  d[rn]=nm
print(d)
Q9.Accept a roll number from the user and display its name from the following dictionary.
D= {1: ‘Amit’, 2: ‘Sumit’, 5: ‘Kavita’}
2
Ansd={1: ‘Amit’, 2: ‘Sumit’, 5: ‘Kavita’}
rn=int(input(“enter roll number”))
if rn in d:
  print(d[rn])
else:
  print(“Record not found”)
Q10.Explain the following in reference to dictionary.
1.       del statement
2.       pop() method
2
AnsDel statement will delete an item from the dictionary by specifying its key. For example
d={1: ‘Amit’, 2: ‘Sumit’, 5: ‘Kavita’}
del d[5]
print(d)
 
Output :
{1: ‘Amit’, 2: ‘Sumit’}

pop( ) : This method not only delete the item from the dictionary but also return the deleted value.
d={1: ‘Amit’, 2: ‘Sumit’, 5: ‘Kavita’}
print(d.pop(1))
print(d)
 
Output:
Amit
{2: ‘Sumit’, 5: ‘Kavita’}
Q11Write the output of the following:
d={1: ‘Amit’, 2: ‘Sumit’, 5: ‘Kavita’}
print(len(d))
print(d.get(2))
d.pop(5)
print(d)
d.clear()
print(d)
a=list(d.items())
print(a)
print(len(a))
6
Ans.3
Sumit
{1: ‘Amit’, 2: ‘Sumit’}
{ }
[ ]
0
Python Dictionary

Python Dictionary Online Quiz

Class 11 IP Chapter wise MCQ
Python Dictionary

Total MCQ – 30

Total Marks – 30

Click here to start QUIZ-#1

Click here to start QUIZ-#2

Click here to start QUIZ-#3


Click for Online Quiz on String

Click for Online Quiz on List

Click for Online Quiz on Python Fundamental


Class 12 Computer Science Sample Paper 2020-2021.

Class 12 Computer Science Sample Paper Marking Scheme

Class 12 Computer Science Test Series


Share with others

Leave a Reply

error: Content is protected !!