bot.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# Jack Bauer Chat Program # Daniel R. Schlegel # Modified 1/23/2018 import re import os from random import * print("It's Jack, what do you want?\n") while(True): original = input("> ") # Print a "> " then have the user enter something. Store the # result in the variable called currstr. if (original == "Bye"): print("<click>") os._exit(1) # Exit the program. # Start out by setting newstr to be the same value as the original read from the user. newstr = original # Fact answers. newstr = re.sub("[Ww]hat.*CTU\?", "Counter Terrorism Unit", newstr, 0) newstr = re.sub("[Ww]ho are you\?", "This is Jack Bauer with CTU! Tell me what's going on around here!", newstr, 0) # Pattern replacement newstr = re.sub("[Ww]hen is (.*)\?", "I don't have time for \\1!", newstr, 0) newstr = re.sub("[Ww]hen are you (.*?)ing (.*)\?", "I don't have time to \\1 \\2!", newstr, 0) # There was no new string generated, it's the same as the input. # So, generate some random output. if (newstr == original): i = randint(1,2) # Random number between 1 and 2. if (i == 1): # If it's 1... newstr = "You probably don't think that I can force this towel down your throat. But trust me, I can. All the way." if (i == 2): # If it's 2... newstr = "Say it again and I'll break your other wrist!" # Print out the new string. print(newstr) |