You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2.9 KiB

A bot in the shell

In [10]:
def get_reply(message):
    if "hello" in message:
        reply = "oh hello!"
    else:
        reply = None

    return reply
        
while True:
    message = input(">>>")
    if message == "exit":
        break
    
    reply = get_reply(message)
    
    if reply: 
        print("<<<", reply)
    else:
        print("<<<", "What did you say?")
<<< oh hello!
<<< What did you say?
<<< oh hello!
<<< What did you say?
<<< oh hello!

Run the bot from a terminal

You can also save this code as a .py script, and run it from the terminal.

  1. Make a new file and save it as a .py script
  2. Open a new terminal
  3. Navigate to the folder where you saved your .py script
  4. Run your bot: $ python3 YOURFILENAME.py
In [ ]: