{"id":1242,"date":"2018-01-27T15:13:02","date_gmt":"2018-01-27T15:13:02","guid":{"rendered":"https:\/\/danielschlegel.org\/wp\/?page_id=1242"},"modified":"2018-01-27T15:13:02","modified_gmt":"2018-01-27T15:13:02","slug":"simple-python-chatbot","status":"publish","type":"page","link":"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/","title":{"rendered":"Simple Python Chatbot"},"content":{"rendered":"<h2>bot.py<\/h2>\n<pre>\r\n# Jack Bauer Chat Program\r\n# Daniel R. Schlegel\r\n# Modified 1\/23\/2018\r\n\r\nimport re\r\nimport os\r\nfrom random import *\r\n\r\nprint(\"It's Jack, what do you want?\\n\")\r\nwhile(True):\r\n    original = input(\"> \") # Print a \"> \" then have the user enter something. Store the\r\n                           # result in the variable called currstr.\r\n    if (original == \"Bye\"):\r\n        print(\"<click>\")\r\n        os._exit(1) # Exit the program.\r\n    \r\n    # Start out by setting newstr to be the same value as the original read from the user.\r\n    newstr = original\r\n    \r\n    # Fact answers.\r\n    newstr = re.sub(\"[Ww]hat.*CTU\\?\", \"Counter Terrorism Unit\", newstr, 0)\r\n    newstr = re.sub(\"[Ww]ho are you\\?\", \"This is Jack Bauer with CTU! Tell me what's going on around here!\", newstr, 0)\r\n    \r\n    # Pattern replacement\r\n    newstr = re.sub(\"[Ww]hen is (.*)\\?\", \"I don't have time for \\\\1!\", newstr, 0)\r\n    newstr = re.sub(\"[Ww]hen are you (.*?)ing (.*)\\?\", \"I don't have time to \\\\1 \\\\2!\", newstr, 0)\r\n    \r\n    # There was no new string generated, it's the same as the input.\r\n    # So, generate some random output. \r\n    if (newstr == original):\r\n        i = randint(1,2) # Random number between 1 and 2.\r\n        if (i == 1): # If it's 1... \r\n            newstr = \"You probably don't think that I can force this towel down your throat. But trust me, I can. All the way.\"\r\n        if (i == 2): # If it's 2...\r\n            newstr = \"Say it again and I'll break your other wrist!\"\r\n    \r\n    # Print out the new string. \r\n    print(newstr)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p class=\"lead\">bot.py # Jack Bauer Chat Program # Daniel R. Schlegel # Modified 1\/23\/2018 import re import os from random import * print(&#8220;It&#8217;s Jack, what do you want?\\n&#8221;) while(True): original = input(&#8220;> &#8220;) # Print a &#8220;> &#8221; then have the user enter something. Store the # result in the variable called currstr. if (original == &#8220;Bye&#8221;): print(&#8220;&#8221;) os._exit(1) # Exit&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"btn btn-warning\" href=\"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1138,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","footnotes":""},"class_list":["post-1242","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Simple Python Chatbot - Daniel R. Schlegel<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Simple Python Chatbot - Daniel R. Schlegel\" \/>\n<meta property=\"og:description\" content=\"bot.py # Jack Bauer Chat Program # Daniel R. Schlegel # Modified 1\/23\/2018 import re import os from random import * print(&quot;It&#039;s Jack, what do you want?n&quot;) while(True): original = input(&quot;&gt; &quot;) # Print a &quot;&gt; &quot; then have the user enter something. Store the # result in the variable called currstr. if (original == &quot;Bye&quot;): print(&quot;&quot;) os._exit(1) # Exit&hellip;Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/\" \/>\n<meta property=\"og:site_name\" content=\"Daniel R. Schlegel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/cog376-spring-2018\\\/simple-python-chatbot\\\/\",\"url\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/cog376-spring-2018\\\/simple-python-chatbot\\\/\",\"name\":\"Simple Python Chatbot - Daniel R. Schlegel\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/#website\"},\"datePublished\":\"2018-01-27T15:13:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/cog376-spring-2018\\\/simple-python-chatbot\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/cog376-spring-2018\\\/simple-python-chatbot\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/cog376-spring-2018\\\/simple-python-chatbot\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Teaching\",\"item\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"COG376 Spring 2018\",\"item\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/cog376-spring-2018\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Simple Python Chatbot\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/#website\",\"url\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/\",\"name\":\"Daniel R. Schlegel\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Simple Python Chatbot - Daniel R. Schlegel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/","og_locale":"en_US","og_type":"article","og_title":"Simple Python Chatbot - Daniel R. Schlegel","og_description":"bot.py # 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(\"\") os._exit(1) # Exit&hellip;Read more","og_url":"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/","og_site_name":"Daniel R. Schlegel","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/","url":"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/","name":"Simple Python Chatbot - Daniel R. Schlegel","isPartOf":{"@id":"https:\/\/danielschlegel.org\/wp\/#website"},"datePublished":"2018-01-27T15:13:02+00:00","breadcrumb":{"@id":"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/simple-python-chatbot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/danielschlegel.org\/wp\/"},{"@type":"ListItem","position":2,"name":"Teaching","item":"https:\/\/danielschlegel.org\/wp\/teaching\/"},{"@type":"ListItem","position":3,"name":"COG376 Spring 2018","item":"https:\/\/danielschlegel.org\/wp\/teaching\/cog376-spring-2018\/"},{"@type":"ListItem","position":4,"name":"Simple Python Chatbot"}]},{"@type":"WebSite","@id":"https:\/\/danielschlegel.org\/wp\/#website","url":"https:\/\/danielschlegel.org\/wp\/","name":"Daniel R. Schlegel","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/danielschlegel.org\/wp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P83Tb6-k2","_links":{"self":[{"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages\/1242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/comments?post=1242"}],"version-history":[{"count":2,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages\/1242\/revisions"}],"predecessor-version":[{"id":1244,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages\/1242\/revisions\/1244"}],"up":[{"embeddable":true,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages\/1138"}],"wp:attachment":[{"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/media?parent=1242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}