<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Node.IS]]></title><description><![CDATA[Node.IS]]></description><link>https://devblog.meemainseen.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 09:37:41 GMT</lastBuildDate><atom:link href="https://devblog.meemainseen.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Mad Lib: A mini Python project]]></title><description><![CDATA[Few words on output and input files
Here's a small video clip showing the output. I am using powershell to navigate to a folder saved on my desktop and running the Python file titled MadLib inside powershell.
https://youtu.be/-H5JhjRzXOU
To begin wit...]]></description><link>https://devblog.meemainseen.com/mad-lib-a-mini-python-project</link><guid isPermaLink="true">https://devblog.meemainseen.com/mad-lib-a-mini-python-project</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><dc:creator><![CDATA[Muhammad Imran Saeed]]></dc:creator><pubDate>Mon, 27 Jan 2020 01:07:53 GMT</pubDate><content:encoded><![CDATA[<h1 id="few-words-on-output-and-input-files">Few words on output and input files</h1>
<p>Here&#39;s a small video clip showing the output. I am using powershell to navigate to a folder saved on my desktop and running the Python file titled MadLib inside powershell.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://youtu.be/-H5JhjRzXOU" data-card-controls="0" data-card-theme="light">https://youtu.be/-H5JhjRzXOU</a></div>
<p>To begin with we used &quot;Romeo Juliet Prologue : AD-LIB&quot; from https://www.madtakes.com/libs. Please feel free to choose any catchphrase of your choice or make one. Following two pictures show the key words required to be input by user and how they show up in the Mad Lib returned by Python when the function runs. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1580083285852/RV8h9AMMx.jpeg" alt="source.JPG">
A screenshot from madtakes.com showing the required input from the user.
Please note the sequence. We can seek user input in python in any order but we will be following this sequence while placing these words in the generated Mad Lib. More on it in a while. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1580083583315/YokM5Q0ly.jpeg" alt="madlib.JPG">
Output Mad Lib generated by Python. We got the phrase from madtakes.com by generating Mad Lib after submitting the input vlaues.</p>
<h1 id="code">Code</h1>
<p>Alright! let&#39;s dive in the shallow waters of a simple code. First we define a variable story which contains the exact Mad Lib phrase as in the above picture. Please note that &#39;story&#39; is a multi line string so we are enclosing it in three quotes (&#39;&#39;&#39;). Please note the use of curly bracket {} in place of words that will be sought through user input. These are the words you see enclosed in yellow rectangles on the picture above. </p>
<pre><code><span class="hljs-attr">story</span> = <span class="hljs-string">'''
Two {}, both alike in dignity,
In fair {}, where we lay our scene,
From ancient {} break to new mutiny,
Where civil blood makes civil hands unclean.
From forth the fatal loins of these two foes
A pair of star-cross`d {} take their life;
Whole misadventured piteous overthrows
Do with their {} bury their parents` strife.
The fearful passage of their {} love,
And the continuance of their parents` rage,
Which, but their children`s end, nought could {},
Is now the {} hours` traffic of our stage;
The which if you with {} {} attend,
What here shall {}, our toil shall strive to mend.
'''</span>
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1580084548075/Qbd2cXfF2.jpeg" alt="source.JPG">
There&#39;s a reason for repeating this picture here. We will seek these values from user using input method in Python. Following line of code seeks input and assigns it to variable named place. </p>
<pre><code><span class="hljs-attr">place</span> = input(<span class="hljs-string">'Enter a location (e.g., London or school): '</span>)
</code></pre><p>We can change the input method for the variables that are sought more than once. For example there are two Singular Nouns, equal number of Plural Nouns and Verbs. We can define Singular Noun as an empty list and use append method to assign input to values to the empty list. We can then recall these values using List[item] method. Following example elaborates it further. </p>
<pre><code>singular_nouns = []
singular_nouns.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter a singular noun (e.g., chair): '</span>))
singular_nouns.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter another singular noun (e.g., table): '</span>))
</code></pre><p>Following is the complete code for seeking input on all 11 values with six values combined into three lists. Please note the input does not follow the sequence in which these will be placed in our Mad Lib rendered by Python. </p>
<pre><code>singular_nouns = []
singular_nouns.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter a singular noun (e.g., chair): '</span>))
singular_nouns.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter another singular noun (e.g., table): '</span>))

plural_nouns = []
plural_nouns.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter a plural noun (e.g., chairs): '</span>))
plural_nouns.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter another plural noun (e.g., tables): '</span>))

adjectives = []
adjectives.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter and adjective (e.g., big): '</span>))
adjectives.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter another adjective (e.g., happy): '</span>))

verbs = []
verbs.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter a verb (e.g., run): '</span>))
verbs.<span class="hljs-built_in">append</span>(input(<span class="hljs-string">'Enter another verb (e.g., play): '</span>))

place = input(<span class="hljs-string">'Enter a location (e.g., London or school): '</span>)
number = input(<span class="hljs-string">'Enter a number (0 - 9): '</span>)
body_part = input(<span class="hljs-string">'Enter a body part (e.g., arm): '</span>)
</code></pre><p>Next we will apply .format function to story variable listing the input variables. Please note that input variables here appear in the exact same sequence in which these will appear in place of curly bracket {} in the story string. Following code applies the format function to story and assigns it to a new variable mad_lib. </p>
<pre><code>mad_lib = story.format (plural_nouns[<span class="hljs-number">0</span>],
                        place,
                        singular_nouns[<span class="hljs-number">0</span>],
                        plural_nouns[<span class="hljs-number">1</span>],
                        singular_nouns[<span class="hljs-number">1</span>],
                        adjectives[<span class="hljs-number">0</span>],
                        verbs[<span class="hljs-number">0</span>],
                        <span class="hljs-built_in">number</span>,
                        adjectives[<span class="hljs-number">1</span>],
                        body_part,
                        verbs[<span class="hljs-number">1</span>])
</code></pre><p>In the end we need to print(mad_lib). To be able to do that we will wrap all input values, the mad_lib variable and print(mad_lib) in a function called main and will call main()
Here&#39;s the full code ....</p>
<pre><code>story = <span class="hljs-string">'''
Two {}, both alike in dignity,
In fair {}, where we lay our scene,
From ancient {} break to new mutiny,
Where civil blood makes civil hands unclean.
From forth the fatal loins of these two foes
A pair of star-cross`d {} take their life;
Whole misadventured piteous overthrows
Do with their {} bury their parents` strife.
The fearful passage of their {} love,
And the continuance of their parents` rage,
Which, but their children`s end, nought could {},
Is now the {} hours` traffic of our stage;
The which if you with {} {} attend,
What here shall {}, our toil shall strive to mend.
'''</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span>

    singular_nouns = []
    singular_nouns.append(input(<span class="hljs-string">'Enter a singular noun (e.g., chair): '</span>))
    singular_nouns.append(input(<span class="hljs-string">'Enter another singular noun (e.g., table): '</span>))

    plural_nouns = []
    plural_nouns.append(input(<span class="hljs-string">'Enter a plural noun (e.g., chairs): '</span>))
    plural_nouns.append(input(<span class="hljs-string">'Enter another plural noun (e.g., tables): '</span>))


    adjectives = []
    adjectives.append(input(<span class="hljs-string">'Enter and adjective (e.g., big): '</span>))
    adjectives.append(input(<span class="hljs-string">'Enter another adjective (e.g., happy): '</span>))

    verbs = []
    verbs.append(input(<span class="hljs-string">'Enter a verb (e.g., run): '</span>))
    verbs.append(input(<span class="hljs-string">'Enter another verb (e.g., play): '</span>))

    place = input(<span class="hljs-string">'Enter a location (e.g., London or school): '</span>)
    number = input(<span class="hljs-string">'Enter a number (0 - 9): '</span>)
    body_part = input(<span class="hljs-string">'Enter a body part (e.g., arm): '</span>)

    mad_lib = story.format (plural_nouns[<span class="hljs-number">0</span>],
                            place,
                            singular_nouns[<span class="hljs-number">0</span>],
                            plural_nouns[<span class="hljs-number">1</span>],
                            singular_nouns[<span class="hljs-number">1</span>],
                            adjectives[<span class="hljs-number">0</span>],
                            verbs[<span class="hljs-number">0</span>],
                            number,
                            adjectives[<span class="hljs-number">1</span>],
                            body_part,
                            verbs[<span class="hljs-number">1</span>])
    print(mad_lib)

main()
</code></pre><p>Enjoy!
p.s. 
Inspired from python video series by KnightLab (available on youtube : https://www.youtube.com/playlist?list=PLhP5GzqIk6qsYjU_3tod0nqoWGXlq9RvF)
I am a newbie to developing and this is my first blog. Please do highlight the mistakes for correction and my learning. </p>
]]></content:encoded></item></channel></rss>