Computer Science, asked by mohdkamran1232, 8 hours ago

write a program to difine a dictionary D in which take enter a word and its opposite as key value pair till the users wish. then only display the opposite of that word which the program asks the user to enter

Answers

Answered by Equestriadash
4

The following co‎des have been written using Python.

opp_dict = dict()

while True:

   key = input("Enter a word/Type 'end' to finish: ")

   if key == 'end' or key == 'End':

       break

   else:

       value = input("Enter its opposite: ")

       opp_dict[key] = value

   print()

print()

rev_opp_dict = dict()

s = 0

lk = list(opp_dict.keys())

lv = list(opp_dict.values())

while s < len(lk):

   rev_opp_dict[lv[s]] = lk[s]

   s = s + 1

w = input("Enter a word: ")

if w in opp_dict.keys():

   print("The opposite of", "'" + w + "'", "is", "'" + opp_dict[w] + "'.")

elif w in rev_opp_dict.keys():

   print("The opposite of", "'" + w + "'", "is", "'" + rev_opp_dict[w] + "'.")

else:

   print("Oops! We don't know the opposite of", "'" + w + "'.")

Similar questions