24. Write a Python program to input 'n' classes and names of their class teachers to store them in a dictionary
and display the same. Also accept a particular class from the user and display the name of the class
teacher of that class.
Answers
Answer:
schooldict ={}
no_of_class=int(input('Enter the number of classes:'))
for x in range(1,no_of_class+1):
schooldict[x] = input('Enter the teacher names:')
print("Display:")
print(schooldict)
classId=int(input('Enter class Id:'))
if classId in schooldict:
print ("teacher name: " + str(schooldict[classId]) + "\n")
Explanation:
n = int(input("Enter the number of classes you'd like to enter details for: "))
print()
Class_dict = dict()
for i in range(n):
x = input("Enter the Class: ")
y = input("Enter the Class Teacher's name: ")
Class_dict[x] = y
print()
print()
print("This is your given dictionary: ")
for i in Class_dict:
print(i, "\t", Class_dict[i])
print()
d = input("Enter the class you'd like to view from the dictionary: ")
if d in Class_dict:
print(d, ":", Class_dict[d])
else:
print("No such class.")