{"id":102,"date":"2024-10-28T06:10:32","date_gmt":"2024-10-28T10:10:32","guid":{"rendered":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/?p=102"},"modified":"2025-04-08T04:32:37","modified_gmt":"2025-04-08T08:32:37","slug":"the-story-of-how-i-made-a-comedy-machine-in-pursuit-of-endless-humor","status":"publish","type":"post","link":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/2024\/10\/28\/the-story-of-how-i-made-a-comedy-machine-in-pursuit-of-endless-humor\/","title":{"rendered":"The Story of How I Made a Comedy Machine in Pursuit of Endless Humor &#8211; Intro Post 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi, this is Aiden again and this is my Coding Assignment for my Fusion 10 program.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pastebin.com\/7JLLJMjp\">This<\/a> is the link to my Python program. The code&#8217;s a little too long to show, but it&#8217;s a comedy machine that can generate jokes based on a subject and object input. You can choose to generate 1-10 jokes. You also get the option to choose an adjective if you select 10 jokes. The machine can regenerate jokes as many times as you want.<\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-c020569f wp-block-group-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"541\" height=\"1024\" src=\"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-2-541x1024.png\" alt=\"\" class=\"wp-image-110\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-2-541x1024.png 541w, https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-2-159x300.png 159w, https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-2-768x1453.png 768w, https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-2-812x1536.png 812w, https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-2-1083x2048.png 1083w\" sizes=\"auto, (max-width: 541px) 100vw, 541px\" \/><\/a><\/figure>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\"><em>The flowchart for the program, slightly simplified<\/em><\/p>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">So basically how the COMEDY MACHINE works is: it goes through the main stuff, <em>print(&#8220;comedy machine v1.0&#8221;),<\/em> etc. Then it calls the function <em>switch(),<\/em> which is just a y\/n verification to the next part.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After that, if your input is &#8220;y&#8221;, it&#8217;ll call the function which everything is based on: <em>firststage().<\/em> (it just quits if you type &#8220;n&#8221;)<\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-c020569f wp-block-group-is-layout-flex\">\n<pre class=\"wp-block-code\"><code># firststage() houses all the jokes and jokesets for generation if humorlvl is set to 1.\ndef firststage():\n    global jokesub1, jokeobj1, jokeadj1\n    # this defines jokeset so that it can be converted to an int.\n    jokeset = jokeset_func()\n    try:\n        jokeset_int = int(jokeset)\n    except ValueError:\n        jokeset_int = None\n\n    # this is the error message for if the user doesn't input a number or a valid code.\n    if jokeset_int is None:\n        print(\"invalid code\")\n        firststage()\n    # this is the error message for if the user inputs a number that is not between 1 and 10.\n    if jokeset_int is not None and jokeset_int &lt; 0 or jokeset_int &gt; 10:\n        print(\"please input a number from 1-10.\")\n        firststage()\n\n    # this is the generation for if jokeset is from 1-9.\n    elif jokeset_int is not None and jokeset_int &gt;= 1 and jokeset_int &lt; 10:\n        print(\"great\")\n        time.sleep(0.5)\n        jokesub1 = str(input(\"enter a subject: \"))\n        jokeobj1 = str(input(\"enter an object: \"))\n        print(\"great\")\n        time.sleep(0.5)\n        verification01 = str(input(\"would you like to generate the jokes? (y\/n) \"))\n        if verification01 == \"n\":\n            firststage()\n        if verification01 == \"y\":\n            for i in range(jokeset_int):\n                joke = jokemaker()\n                print(joke)\n                time.sleep(0.2)\n            verification001 = str(input(\"would you like to regenerate the jokes?: (y\/n) \"))\n            if verification001 == \"y\":\n                refirststage()\n            if verification001 == \"n\":\n                print(\"thank you for using the comedy machine.\")\n                time.sleep(1)\n                os.system(\"cls\")\n                print(\"the comedy machine will always return.\")\n                time.sleep(1)\n                exit()\n            else:\n                print(\"please choose between y or n.\")\n\n    # this is the generation for if jokeset is 10.\n    elif jokeset_int is not None and jokeset_int == 10:\n        print(\"great\")\n        time.sleep(0.5)\n        jokesub1 = str(input(\"enter a subject: \"))\n        jokeobj1 = str(input(\"enter an object: \"))\n        jokeadj1 = str(input(\"enter an adjective: \"))\n        print(\"great\")\n        time.sleep(0.5)\n        verification01 = str(input(\"would you like to generate the jokes?: (y\/n) \"))\n        if verification01 == \"n\":\n            firststage()\n        if verification01 == \"y\":\n            for i in range(jokeset_int):\n                joke = premiumjokemaker()\n                print(joke)\n                time.sleep(0.2)\n            verification001 = str(input(\"would you like to regenerate the jokes?: (y\/n) \"))\n            if verification001 == \"y\":\n                refirststage()\n            if verification001 == \"n\":\n                print(\"thank you for using the comedy machine.\")\n                time.sleep(1)\n                os.system(\"cls\")\n                print(\"the comedy machine will always return.\")\n                time.sleep(1)\n                exit()\n            else:\n                print(\"please choose between y or n.\")<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\"><em>The code for <\/em>firststage().<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-c020569f wp-block-group-is-layout-flex\">\n<pre class=\"wp-block-code\"><code># jokeset_func() receives input for the jokeset.\ndef jokeset_func():\n    jokeset = str is(input(\"how many jokes would you like to generate?: (1-10, codes allowed) \"))\n    return jokeset<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\"><em>The code for <\/em>jokeset_func(), <em>used in the first part of <\/em>firststage().<\/p>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s quite simple. At first it globalizes <em>jokesub1, jokeobj1, <\/em>and <em>jokeadj1<\/em> in order for the variables to work. Then it calls<em> jokeset_func(),<\/em> which asks for input on <em>jokeset<\/em> from 1-10. It then returns the value to <em>firststage().<\/em> Back in <em>firststage(),<\/em> it does a little <em>try<\/em> block to test <em>jokeset<\/em> if it has a ValueError and converts it into a None, which means it&#8217;s neither a string or an integer, but it pretty much means a string here. Then it&#8217;s just code for error messages in case you put either a string or a number that isn&#8217;t between 1-10.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After that we get to the heart of <em>firststage(). <\/em>It is an <em>elif<\/em> statement when <em>jokeset_int<\/em> is not None and it is &gt;= 1 or &lt; 10. Then it prints some junk like &#8220;great&#8221; and asks for input on <em>jokesub1 <\/em>and <em>jokeobj1,<\/em> which are the subject and object variables, in case they weren&#8217;t obvious already. Once you&#8217;re done, it prints more &#8220;great&#8221; junk and requests a y\/n input via <em>verification01.<\/em> If you input &#8220;n&#8221;, you get sent back to <em>firststage().<\/em> If you input &#8220;y&#8221;, it prints a number of jokes depending on <em>jokeset_int<\/em> in a <em>for <\/em>loop.<\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-c020569f wp-block-group-is-layout-flex\">\n<pre class=\"wp-block-code\"><code>\"\"\"\nthis is the jokemaker for if jokeset is from 1-9. it takes random jokes from the jokelist and \nreplaces the variables with the user's input.\n\"\"\"\ndef jokemaker():\n    global jokesub1, jokeobj1\n    joketemp = random.choice(jokelist)\n    joke = joketemp.replace(\"{jokesub1}\", jokesub1).replace(\"{jokeobj1}\", jokeobj1)\n    return joke<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\"><em>This is the code for <\/em>jokemaker(), <em>the key function for generating jokes from the <\/em>jokelist.<\/p>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In the <em>for<\/em> loop, it calls <em>jokemaker(),<\/em> which selects a random joke from the <em>jokelist<\/em> through <em>random.choice.<\/em> Then it replaces <em>{jokesub1} <\/em>and <em>{jokeobj1}<\/em> (which are present in the joke templates as variable placeholders) with the variables themselves. It then returns everything to <em>firststage().<\/em> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In <em>firststage(),<\/em> after calling <em>jokemaker(),<\/em> it converts its&#8217; value to <em>joke<\/em>. Then it loops <em>print(&#8220;joke&#8221;)<\/em> and <em>time.sleep(0.2)<\/em> (which delays the program) as many times as <em>jokeset_int.<\/em> Once it&#8217;s done, it again asks for a y\/n input for joke regeneration through <em>verification001.<\/em> (creative, I know) If you type &#8220;n&#8221;, it prints some &#8220;thank you&#8221; stuff along with a cryptic &#8220;we will return&#8221; message. If you type &#8220;y&#8221;, it calls <em>refirststage(), <\/em>which as you guessed, is basically <em>firststage(), <\/em>but with some minor differences.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember what I said about 10 having an adjective as an option? Well, in the case that you put 10 into <em>jokeset_int, <\/em>it will basically do the same except it also asks you for <em>jokeadj1<\/em> and chooses jokes from the <em>premiumjokelist,<\/em> which includes adjective variables in its jokes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This project was on another level of frustration from my previous project. While being theoretically simple, this project was actually quite difficult as I had only learned basic Python beforehand. At first, I had planned to put 10 different levels for the comedy machine, hence the name <em>firststage()<\/em> for the function, but it soon got too tedious to code as I was struggling to make even the most basic mode work. The joke part was easy. Learning to use <em>try<\/em> blocks and <em>f-strings<\/em> in lists with an AI that went off the rails every 2 prompts was hard.<\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-c020569f wp-block-group-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-old-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"728\" src=\"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-old-1-1024x728.png\" alt=\"\" class=\"wp-image-116\" srcset=\"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-old-1-1024x728.png 1024w, https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-old-1-300x213.png 300w, https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-old-1-768x546.png 768w, https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-old-1-1536x1092.png 1536w, https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-content\/uploads\/sites\/12\/2024\/10\/fusion-one-flowchart-old-1-2048x1456.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\"><em>The original flowchart for the comedy machine. Note how instead of drawing jokes from a list, each number had its own unique jokes, which made it really boring.<\/em><\/p>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see from this crazy-looking flowchart, each number would have a unique set of jokes, as I hadn&#8217;t learnt how to use <em>random.choice() <\/em>or <em>replace().<\/em> The AI had really helped me in places like those. I had also used the AI to generate the jokes present in the <em>premiumjokelist, <\/em>as I was tired of writing them. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I had learned a lot about Python in this project. From recursion to clearing the screen, I now feel a little more comfortable coding with it than before I started. I had also learned to control my frustration many, MANY times in this project. For example, early on in the project, I tried to implement codes into the input of <em>jokeset_int.<\/em> That didn&#8217;t work very well. It always gave me a ValueError, and the AI was being really dumb and giving me the wrong fixes. I had to do a crash course on variable types as well as <em>try<\/em> blocks to figure out how to fix it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I feel like this project has a lot of potential and places to improve on. From a bigger <em>jokelist<\/em> to being able to save jokes or suggest new ones, the comedy machine can be something a lot more. However, for the time being, I think I&#8217;m gonna take a brain break and mess around with it for a little bit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Aiden<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, this is Aiden again and this is my Coding Assignment for my Fusion 10 program. This is the link to my Python program. The code&#8217;s a little too long to show, but it&#8217;s a comedy machine that can generate jokes based on a subject and object input. You can choose to generate 1-10 jokes. [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-102","post","type-post","status-publish","format-standard","hentry","category-intro"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/posts\/102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/comments?post=102"}],"version-history":[{"count":13,"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/posts\/102\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/posts\/102\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/media?parent=102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/categories?post=102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.stgeorges.bc.ca\/aidenh\/wp-json\/wp\/v2\/tags?post=102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}