-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
45 lines (30 loc) · 929 Bytes
/
bot.py
File metadata and controls
45 lines (30 loc) · 929 Bytes
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
#!/usr/bin/env python3
#====#^#====#
# Imports
import random
import json
import os
#====#^#====#
# Colors
cyan = '\033[1;96m' # Cyan
reset = '\033[0m' # Reset
#====#^#====#
# Clear Terminal
os.system("cls" if os.name == "nt" else "clear")
print(f"{cyan}Hi! Let's talk...")
#====#^#====#
# Brain
with open('brain.json', 'r+') as _brain:
brain = dict(json.load(_brain))
learned = len(brain)
print(f"{cyan}Learned words:{reset} {learned}")
while True:
user_input = input(f"\n{cyan}>>>{reset} ") .lower().strip()
if user_input[-1] == "?":
user_input = user_input.split("?")[0].strip()
try:
print(f"{cyan}" + brain[user_input])
except KeyError:
learn = input(f"{cyan}{user_input}{reset}\n\n{cyan}>>>{reset} ")
brain[user_input] = learn
json.dump(brain, open("brain.json", 'w'), indent=4 )