Posts

Showing posts from March, 2026

Loop based Math Chat Agent in Python

print ( "🤖 Simple AI Chat Agent" ) print ( "Type 'exit' anytime to stop\n" ) #creating empty list to store the chats later chat_history = [] #creating function for mathematical calculations since its a math chat agent def calculations ( expression ):     try :         result = eval (expression)         return f "The answer is {result} "     except :         return "I couldn’t understand that.please use numbers instead of letters" #creating function for storing message, how and what to respond def chatrespond ( usermessage ):     usrmsg = usermessage.lower()     chat_history.append(usermessage)     # Greetings - when user says hello     if "hello" in usrmsg or "hi" in usrmsg:         return "Hello! How can I help you?"     # when user asks How are you     if "how are you" in usrmsg:         retu...