Building a Python Chatbot
This is something I've wanted to learn for a long time. It happens that users sometimes leave a bot idle for a long time which for a robot aiming to pass the Turing test would be undesirable as it would break realism. The idea is that when you leave your friend without reply, he doesn't freeze while waiting for you to reply and interact again. So I programmed a small Python chatbot that performs a random action whenever its left idle for a certain amount of time.
The application is pretty basic and based on StackOverflow's post of timed input. IMO, it can be useful for more complex projects.
The application is pretty basic and based on StackOverflow's post of timed input. IMO, it can be useful for more complex projects.
|
This was made by StackOverflow, not me.
THE CODE: import sys, select print("You have ten seconds to answer!") i, o, e = select.select( [sys.stdin], [], [], 10 ) if (i): print("You said", sys.stdin.readline().strip()) else: print("You said nothing!") |