Skip to content

Commit 88757ed

Browse files
Merge pull request #1597 from Soumya-Kushwaha/calculator
Added AI Calculator
2 parents 52a98b1 + 9e73558 commit 88757ed

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

AI Calculator/main.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from chatterbot import ChatBot
2+
3+
# naming the ChatBot calculator
4+
# using mathematical evaluation logic
5+
# the calculator AI will not learn with the user input
6+
Bot = ChatBot(name = 'Calculator',
7+
read_only = True,
8+
logic_adapters = ["chatterbot.logic.MathematicalEvaluation"],
9+
storage_adapter = "chatterbot.storage.SQLStorageAdapter")
10+
11+
12+
# clear the screen and start the calculator
13+
print('\033c')
14+
print("Hello, I am a calculator. How may I help you?")
15+
while (True):
16+
# take the input from the user
17+
user_input = input("me: ")
18+
19+
# check if the user has typed quit to exit the prgram
20+
if user_input.lower() == 'quit':
21+
print("Exiting")
22+
break
23+
24+
# otherwise, evaluate the user input
25+
# print invalid input if the AI is unable to comprehend the input
26+
try:
27+
response = Bot.get_response(user_input)
28+
print("Calculator:", response)
29+
except:
30+
print("Calculator: Please enter valid input.")

0 commit comments

Comments
 (0)