|
import json |
|
import random |
|
|
|
with open("3letterai.json", "r") as f: |
|
ai = json.load(f) |
|
|
|
|
|
def getresp(text): |
|
if len(text) > 3: return "я больше трёх букв не понимаю" |
|
t = text.replace("ъ", "ь").lower() |
|
if t in ai: |
|
o = ai[t] |
|
if type(o) is list: |
|
return random.choice(o) |
|
else: |
|
return o |
|
if text.strip().isnumeric(): |
|
return str(int(text)+1) |
|
if len(t) == 3: |
|
if t[1] == "+": |
|
try: |
|
return f"{int(t[0]) + int(t[1])}, легко" |
|
except ValueError: |
|
pass |
|
elif t[1] == "-": |
|
try: |
|
return f"{int(t[0]) - int(t[1])}, легко" |
|
except ValueError: |
|
pass |
|
elif t[1] == "/": |
|
if t[2] == "0": return "на ноль делить нельзя балбес" |
|
try: |
|
return f"{int(t[0]) / int(t[1])}, легко" |
|
except ValueError: |
|
pass |
|
elif t[1] == "*": |
|
try: |
|
return f"{int(t[0]) * int(t[1])}, легко" |
|
except ValueError: |
|
pass |
|
return random.choice(["ам", "чё", "непон", "сам такой"]) |
|
|
|
|