You are on page 1of 3

Q5:

d={}

n=int(input("Enter the number of elements:"))

for i in range(n):

k=input("Enter the key:")

v=int(input("Enter the value:"))

d[k]=v

x=[]

for i in d.values():

x.append(i)

print(x)

x.sort(reverse=True)

print("The highest number is:", x[0], "and second highest number is:",x[1])

Q6:

d={}

n=int(input("Enter the number of classes:"))

for i in range(n):

k=input("Enter the class:")

v=input("Enter the class teacher:")

d[k]=v

x=input("Enter the class to be checked:")

for i in d.keys():

if x==i:

print("Your class teacher is:",d[i])

Q7:

d={}

n=int(input("Enter the number of students:"))

for i in range(n):

k=input("Enter the name:")

v=int(input("Enter the percent:"))

d[k]=v

x=input("Enter the name of student to be deleted:")

del d[x]

print("The dictionary after deletion is:",d)


Q8:

d={}

n=int(input("Enter the number of customers:"))

for i in range(n):

k=input("Enter the name:")

g=input("Enter the product:")

c=int(input("Enter the cost:"))

p=int(input("Enter the phone number:"))

d[k]=(g,c,p)

for i in d.keys():

print("\nCustomer name:",i)

print("Product\tcost\tphone number")

for j in d[i]:

print(j,end='\t')

Q17:

d={}

n=int(input("Enter the number of products:"))

for i in range(n):

k=input("Enter the product:")

v=int(input("Enter the cost:"))

d[k]=v

x=input("Enter the product to be checked:")

for i in d.keys():

if x==i:

print("The cost is:",d[i])

break

else:

print("The product is unavailable")

break

Q18:

d={}

n=int(input("Enter the number of elements:"))

for i in range(n):

k=input("Enter the key:")


v=input("Enter the value:")

d[k]=v

x=input("Enter the value to be checked:")

for i in d.keys():

if x==d[i]:

print("The value is present")

l=[]

for j in d.values():

l.append(j)

print(x,"is repeated",l.count(d[i]),'times')

print("The key is",i,"and value is",d[i])

else:

print("Error, The value is not found")

-----------------------------------------------------------------------------------------------------------------------------------------------------------

You might also like