-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab5.py
44 lines (31 loc) · 979 Bytes
/
lab5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pprint
dictionary = {}
def add_or_open_word():
new_word = input('Input new English word: ').lower().replace(' ', '')
# END OF PROGRAM
if new_word == 'exit' or new_word == '':
print('DICTIONARY:')
pprint.pprint(dictionary)
exit()
# WORD ALREADY EXISTS
if new_word in dictionary:
print('already exists\n' +
'{0} - {1}'.format(new_word, dictionary[new_word]))
add_or_open_word()
# ADD NEW WORD
dictionary[new_word] = []
print('Enter empty field for closing adding translation')
add_translation(new_word)
# REPEAT ADDING
add_or_open_word()
def add_translation(new_word):
trans = input('Add translation: ')
# IF NOT EMPTY FIELD
if trans:
dictionary[new_word] += [trans]
add_translation(new_word)
def main():
print('Print "exit" for closing program and showing dictionary')
add_or_open_word()
if __name__ == '__main__':
main()