-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_dictionary.py
More file actions
47 lines (36 loc) · 1.13 KB
/
python_dictionary.py
File metadata and controls
47 lines (36 loc) · 1.13 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
import json
import difflib
from difflib import SequenceMatcher, get_close_matches
import random
# lokasi file
lok_file = "files/3.1 data.json.json"
data = json.load(open(lok_file))
# algoritma cari arti
def cari_arti(kata):
kata = kata.lower()
kata = cari_kesamaan(kata)
if kata in data:
rand = random.randint(0, len(data[kata]) - 1)
return data[kata][rand]
else:
return("mohon maaf kata anda tidak ditemukan, silahkan cek kembali kata-kata anda")
def cari_kesamaan(kata):
if kata in data:
return kata
else:
kata = get_close_matches(kata, data.keys())
for i in range(0, len(kata)):
try:
cek = input(
f"apakah kata yang anda maksud adalah {kata[i]} ? ketik ya atau tidak : ")
cek = cek.lower()
cek = get_close_matches(cek, ['ya', "tidak"])[0]
if cek == "ya":
return kata[i]
else:
pass
except:
return("NONONO")
break
masuk = input("Masukkan kata : ")
print(cari_arti(masuk))