This repository was archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise-general-week-05-01-answer.py
More file actions
73 lines (61 loc) · 1.95 KB
/
exercise-general-week-05-01-answer.py
File metadata and controls
73 lines (61 loc) · 1.95 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from tkinter import *
from tkinter import messagebox
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 1 <-----
my_dictionary = {
"red": "قرمز",
"blue": "آبی",
"green": "سبز",
"black": "مشکی",
"white": "سفید",
"yellow": "زرد",
"orange": "نارنجی",
"gray": "خاکستری",
"pink": "صورتی",
"silver": "نقره ای",
"gold": "طلایی",
}
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 3 Part 1 <-----
def clear_text(txt):
txt = txt.replace("آ","ا")
return txt
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 2 <-----
_ = {}
for k, v in my_dictionary.items():
_[v] = clear_text(k)
my_dictionary = _.copy()
del _
print(my_dictionary)
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 3 Part 2 <-----
my_dictionary["سیاه"] = "black"
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def translate():
word = txt.get().strip().lower()
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 3 <-----
word = clear_text(word)
if word in my_dictionary.keys():
lbl.config(text=my_dictionary[word])
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Answer 4,5 <-----
else:
lbl.config(text="موجود نیست")
messagebox.showinfo("دیکشنری","موجود نیست")
print(word)
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
win = Tk()
win.title("نرم افزار دیکشنری")
win.geometry("350x100")
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
txt = Entry(win)
txt.pack()
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lbl = Label(win, text="معنا")
lbl.pack()
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
btn = Button(win, text="ترجمه", command=translate)
btn.pack()
win.mainloop()