Class 11 CBSE - Python Dictionary Programs

Python is designed to understand the user’s responsibility, the protocol, and the ethical issues related to the field of computing.
Python in class 11 for cbse is very handy when it comes to practice on computers but for the beginers there might be some errors and problems such as exception. But it's always advisable to practice program on computer than writing it on paper because it cherishes your practical skills , knowledge and typing speed and you'll come to know new things and if you want to be a software developer someday then its a must call for you.
Program 1: Write a program to input two dictionaries and combine both dictionary values of common keys
Solution:
def combine():
    dic={"x":300,"y":200,"z":100}
    dict1={"y":100,"x":300,"z":500}
    dict3={}
    for i in dict1:
        if i in dic:
            dict3[i]=dic[i]+ dict1[i]
    return dict3


#calling method
dict=combine()
print("Combining two values in dictionary is:",dict)

                        

Program 2: Write a program to input a dictionary and print keys with maximum and minimum values
Solution:
def maxmin():
    max=0
    min=999
    dic={"One":1,"Ten":10,"Zero":0,"Nine":9,"Eleven":11}
    for i in dic:
        if (dic[i]> max):
            max=dic[i]
        elif (dic [i] < min):
            min=dic[i]
    print("Maximum value in the dictionary is:",max)
    print("Minimum value in the dictionary is:",min)

#calling method
maxmin()

                        

Program 3: Write a program in dictionary where keys are numbers from 1 to 20 and values are square of these keys
Solution:
#method for squaring key values

def squaring():
    dic={}
    for number in range(1,21):
        dic[number]=number**2
    return dic


#method calling
new_dict=squaring()
print("Output is",new_dict)
                        

Program 4: Write a program to input a dictionary and multiply all the key values present in dictionary
Solution:
#method to multiply all the items in dictionary
def multiply():
    res=1
    dict={"ele1":12,"ele2":15,"ele3":20,"ele4":40,"ele5":30}

    for i in dict:
        res=res * dict[i]
    return res
    

#method calling
a=multiply()
print ("Multiplication of all the items in a dictionary is:",a)
                        

Program 5: Write a program to enter roll number,names and marks of 5 students and display the name of students who have marks above 90 in computer
Solution:
#Details of students
students={}
for i in range(5):
    print("Enter details of student number ",(i+1))
    rno=int(input("Roll No:"))
    name=input("Name:")
    marks=int(input("Marks in Computer:"))
    students[i+1]=[name,marks]

print("Dictionary of 5 students is")
print(students)


#students who have scored highest marks in computer more than 90
for stu in students:
    if students[stu][1]>75:
        print(students[stu][0])
                        

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com