Page 430 - Computer Science V2.0 Class 11
P. 430

07     '''
                08     Input Parameter: None
                09     Return Value: None
                10     '''
                11
                12     cont = input('Want to add more word and synonyms?(Y/y):')
                13
                14     while cont in ['Y', 'y']:
                15         wordMeans = eval(input('enter word, tuple of synonyms as a tuple:'))
                16         thesaurus[wordMeans[0]] = wordMeans[1]
                17         cont = input('Want to add more word meanings? (Y/y):')
                18
                19     printDict()
                20
                21 def printDict():
                22     '''
                23     Input Parameter: None
                24     Return Value: None
                25     '''
                26
                27     for key in  thesaurus:
                28         print(key, thesaurus[key])
                29
                30     findSynonyms()
                31
                32 def findSynonyms():
                33     '''
                34     Input Parameter: None
                35     Return Value: None
                36     '''
                37     moreWords = input('Do you want synonyms of a word,Reply Y/y of N/n?')
                38     while moreWords in ['Y', 'y']:
                39         synonyms = set()
                40         word = input('Enter a word:')
                41         keys = thesaurus.keys()
                42         for key in thesaurus.keys():
                43             if word in thesaurus[key]:
                44                 synonyms.update(set(thesaurus[key]), {key})
                45             elif key == word:
                46                 synonyms.update(set(thesaurus[key]))
                47         if synonyms == set():
                48             print('No synonyms found')
                49             print('Want to add', word, ' to thesaurus?,Reply Y/y of N/n?')
                50             addSynonym = input()
                51             if addSynonym in ['Y','y']:
                52                 synonyms = eval(input('Enter synonyms as a tuple'))
                53                 thesaurus[word] = synonyms
                54         else:
                55             print('synonyms of ', word, ':', synonyms)
                56
                57         moreWords = input('Do you want synonyms of a word,Reply Y/y of N/n?')
                58
                59
                60 #main segment
                61
                62 engDict()





               416   Touchpad Computer Science (Ver. 2.0)-XI
   425   426   427   428   429   430   431   432   433   434   435