Computer Science, asked by unknown3652, 7 months ago

2.Write a code in Python to declare a dictionary of teacher and his subject. the program should accept names of five teachers and their subjects from the user and add them to the dictionary. then the program should prompt to accept the teacher name and display the corresponding subject. it the teacher name is not found in the list then program should display an appropriate message​

Answers

Answered by Equestriadash
9

Class_dict = dict()

for i in range(5):

   x = input("Enter the name of thr teacher: ")

   y = input("Enter the subject being taught by him/her: ")

   print()

   Class_dict[x] = y

print()

print("This is your given dictionary: ")

for i in Class_dict:

   print(i, "\t", Class_dict[i])

print()

d = input("Enter the name of the teacher whose details you'd like to view: ")

if d in Class_dict:

   print(d, ":", Class_dict[d])

else:

   print("No such teacher found in the given dictionary.")


Equestriadash: Thanks for the Brainliest!
Answered by Anonymous
0

Answer:

Class_dict = dict()

for i in range(5):

   x = input("Enter the name of thr teacher: ")

   y = input("Enter the subject being taught by him/her: ")

   print()

   Class_dict[x] = y

print()

print("This is your given dictionary: ")

for i in Class_dict:

   print(i, "\t", Class_dict[i])

print()

d = input("Enter the name of the teacher whose details you'd like to view: ")

if d in Class_dict:

   print(d, ":", Class_dict[d])

else:

   print("No such teacher found in the given dictionary.")

Similar questions