<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://peda.net/:static/535/atom.xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>LOHKOISTA TEKSTIPOHJSIEEN OHJELMOINTIIN</title>
<id>https://peda.net/id/5537bf947a1</id>
<updated>2018-06-27T18:32:42+03:00</updated>
<link href="https://peda.net/id/5537bf947a1:atom" rel="self" />
<link href="https://peda.net/p/anu.salow%40posio.fi/kccmpp/lto#top" rel="alternate" />
<logo>https://peda.net/:static/535/peda.net.logo.bg.svg</logo>
<rights type="html">&lt;div class=&quot;license&quot;&gt;Tämän sivun lisenssi &lt;a rel=&quot;license&quot; href=&quot;https://peda.net/info&quot;&gt;Peda.net-yleislisenssi&lt;/a&gt;&lt;/div&gt;&#10;</rights>

<entry>
<title>SELKKARI ELI SCRATCH - PYTHON KÄÄNNÖSAPURI</title>
<id>https://peda.net/id/056b1bfa7bb</id>
<updated>2018-06-29T20:01:09+03:00</updated>
<link href="https://peda.net/p/anu.salow%40posio.fi/kccmpp/lto/sespk#top" />
<content type="html">LINKKI TÄSTÄ &lt;br/&gt;&#10;&lt;br/&gt;&#10;&lt;a&gt;&lt;!--filtered attribute: href=&quot;file:///Users/anusalow/Pictures/Cheat-sheet-tunring-Scratch-into-Python-A3-DIGITAL.pdf&quot;--&gt;file:///Users/anusalow/Pictures/Cheat-sheet-tunring-Scratch-into-Python-A3-DIGITAL.pdf&lt;/a&gt;&lt;br/&gt;&#10;&lt;br/&gt;&#10;&lt;br/&gt;&#10;</content>
<published>2018-06-29T20:01:09+03:00</published>
</entry>

<entry>
<title>SCRATCH JA PYTHON SYNTAKSI</title>
<id>https://peda.net/id/6f07b7827bb</id>
<updated>2018-06-29T19:49:48+03:00</updated>
<link href="https://peda.net/p/anu.salow%40posio.fi/kccmpp/lto/sjps#top" />
<content type="html">MATERIAALIA KURSSILTA:&lt;br/&gt;&#10;&lt;br/&gt;&#10;&lt;a href=&quot;https://www.futurelearn.com/courses/block-to-text-based-programming/2/steps/354634#fl-comments&quot; rel=&quot;nofollow ugc noopener&quot;&gt;https://www.futurelearn.com/courses/block-to-text-based-programming/2/steps/354634#fl-comments&lt;br/&gt;&#10;&lt;br/&gt;&#10;&lt;/a&gt;&#10;&lt;p&gt;One aspect of using a text-based language that many learners struggle with is understanding the specific syntax (the rules of the language) required. Mistakes made in a program are often due to these rules not being followed, and are called syntax errors. It is therefore helpful to show the parallels and differences between a language that a learner has already mastered and the one they are trying to learn.&lt;/p&gt;&#10;&lt;p&gt;Shown below are a few Scratch blocks and their equivalent code in Python. The list is far from exhaustive, and is intended as a reference guide rather than an exercise to be worked through.&lt;/p&gt;&#10;&lt;h3&gt;Variable assignment&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;In Scratch, a variable needs to be created before it can be assigned a value, whereas in Python a variable is created upon assignment with a value.&lt;/li&gt;&#10;&lt;li&gt;In Python, it is necessary to surround strings (any text) with either single (&lt;code&gt;'&lt;/code&gt;) or double (&lt;code&gt;&amp;quot;&lt;/code&gt;) quotes.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-1.png&quot; alt=&quot;1-6-1.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Increment a variable&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;In Scratch, a variable’s value can be increased or decreased.&lt;/li&gt;&#10;&lt;li&gt;In Python, a variable’s value can be increased or decreased by reassigning it to itself with the addition or subtraction of a number.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-2.png&quot; alt=&quot;1-6-2.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Simple output&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;In Scratch, you make a sprite talk to provide output to the user of the program.&lt;/li&gt;&#10;&lt;li&gt;Python uses&lt;span&gt; &lt;/span&gt;&lt;code&gt;print&lt;/code&gt;&lt;span&gt; &lt;/span&gt;statements to output to the&lt;span&gt; &lt;/span&gt;&lt;strong&gt;shell&lt;/strong&gt;.&lt;/li&gt;&#10;&lt;li&gt;Again in Python, you need to use single or double quotes if you are printing strings.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-3.png&quot; alt=&quot;1-6-3.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Conditional loops&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Scratch’s conditional loop repeats&lt;span&gt; &lt;/span&gt;&lt;strong&gt;until&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;a certain statement is&lt;span&gt; &lt;/span&gt;&lt;code&gt;True&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;Python’s conditional loop repeats&lt;span&gt; &lt;/span&gt;&lt;strong&gt;as long as&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;a certain statement is&lt;span&gt; &lt;/span&gt;&lt;code&gt;True&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;There needs to be a colon (&lt;code&gt;:&lt;/code&gt;) at the end of the statement in Python.&lt;/li&gt;&#10;&lt;li&gt;Notice that the code that is&lt;span&gt; &lt;/span&gt;&lt;strong&gt;inside&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;the loop is&lt;span&gt; &lt;/span&gt;&lt;strong&gt;indented&lt;/strong&gt;. Indentation is normally four spaces or a single tab. This can be compared to the way the Scratch conditional loop block&lt;span&gt; &lt;/span&gt;&lt;strong&gt;brackets&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;the code within it.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-4.png&quot; alt=&quot;1-6-4.png&quot;/&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;The example above isn’t the simplest way of doing this in Python though. Using the&lt;span&gt; &lt;/span&gt;&lt;code&gt;while&lt;/code&gt;&lt;span&gt; &lt;/span&gt;loop, it is easier to check that the variable is&lt;span&gt; &lt;/span&gt;&lt;strong&gt;less than&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;&lt;code&gt;10&lt;/code&gt;.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&#10;&lt;pre&gt;&lt;code&gt;&lt;span&gt;while&lt;/span&gt; &lt;span&gt;foo&lt;/span&gt; &lt;span&gt;&amp;lt;&lt;/span&gt; &lt;span&gt;10&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&#10;    &lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;foo&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;h3&gt;Infinite loops&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Scratch has a specific type of loop that is infinite.&lt;/li&gt;&#10;&lt;li&gt;In Python, a conditional loop is used that always evaluates to&lt;span&gt; &lt;/span&gt;&lt;code&gt;True&lt;/code&gt;.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-5.png&quot; alt=&quot;1-6-5.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Conditional selection&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Scratch has two selection blocks that can be used. If multiple conditions are required, they need to be nested within each other.&lt;/li&gt;&#10;&lt;li&gt;Python has three selection statements:&lt;span&gt; &lt;/span&gt;&lt;code&gt;if&lt;/code&gt;,&lt;span&gt; &lt;/span&gt;&lt;code&gt;elif&lt;/code&gt;, and&lt;span&gt; &lt;/span&gt;&lt;code&gt;else&lt;/code&gt;. Again colons (&lt;code&gt;:&lt;/code&gt;) and indentation are needed.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-6.png&quot; alt=&quot;1-6-6.png&quot;/&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-7.png&quot; alt=&quot;1-6-7.png&quot;/&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-8.png&quot; alt=&quot;1-6-8.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Testing for equality&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;In Scratch, you can use the equal sign (&lt;code&gt;=&lt;/code&gt;) to test if one value is the same as another value.&lt;/li&gt;&#10;&lt;li&gt;In Python, a single equal sign is reserved for variable assignment, so a double equal sign (&lt;code&gt;==&lt;/code&gt;) is used to test for equality.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-9.png&quot; alt=&quot;1-6-9.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Lists&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Scratch lists are made in much the same way that variables are made.&lt;/li&gt;&#10;&lt;li&gt;In Python, you use square brackets (&lt;code&gt;[]&lt;/code&gt;) when creating a list, with commas between each pair of items.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-18.png&quot; alt=&quot;1-6-18.png&quot;/&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;You can add to a list in both Scratch and Python.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-11.png&quot; alt=&quot;1-6-11.png&quot;/&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;And you can also remove items from lists in both languages. In Scratch the first item in a list is at position&lt;span&gt; &lt;/span&gt;&lt;code&gt;1&lt;/code&gt;. In Python, however, the first item in a list is at position&lt;span&gt; &lt;/span&gt;&lt;code&gt;0&lt;/code&gt;. That’s because in Python, you always start counting from&lt;span&gt; &lt;/span&gt;&lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-12.png&quot; alt=&quot;1-6-12.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Randomness&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Scratch has a&lt;span&gt; &lt;/span&gt;&lt;code&gt;random&lt;/code&gt;&lt;span&gt; &lt;/span&gt;block that can be used to generate random numbers.&lt;/li&gt;&#10;&lt;li&gt;In Python, you need to import the&lt;span&gt; &lt;/span&gt;&lt;code&gt;random&lt;/code&gt;&lt;span&gt; &lt;/span&gt;module.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-13.png&quot; alt=&quot;1-6-13.png&quot;/&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Both languages can also select random items from a list:&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-14.png&quot; alt=&quot;1-6-14.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Concatenation&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Join strings together in Scratch using the&lt;span&gt; &lt;/span&gt;&lt;code&gt;join&lt;/code&gt;&lt;span&gt; &lt;/span&gt;block.&lt;/li&gt;&#10;&lt;li&gt;In Python, you can use the addition operator (&lt;code&gt;+&lt;/code&gt;) to join strings.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-15.png&quot; alt=&quot;1-6-15.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Indexing&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;In both languages, you can find an item in a list or string using the item index.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-16.png&quot; alt=&quot;1-6-16.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Input&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;You can collect user input in Scratch by using the&lt;span&gt; &lt;/span&gt;&lt;code&gt;ask&lt;/code&gt;&lt;span&gt; &lt;/span&gt;block.&lt;/li&gt;&#10;&lt;li&gt;In Python you use the&lt;span&gt; &lt;/span&gt;&lt;code&gt;input()&lt;/code&gt;&lt;span&gt; &lt;/span&gt;function.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-17.png&quot; alt=&quot;1-6-17.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;Type casting&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;In Scratch, strings and integers are intelligently detected. In Python, it is necessary to&lt;span&gt; &lt;/span&gt;&lt;strong&gt;type cast&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;when converting from one to another. For instance, you can change a string to an integer and back again as follows:&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&#10;&lt;pre&gt;&lt;code&gt;&lt;span&gt;number&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;6&lt;/span&gt;&#10;&lt;span&gt;number_as_string&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;str&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;6&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;number_as_integer&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;int&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;number_as_string&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;Cheat sheets for these comparisons are available at the bottom of this step in both digital and print formats.&lt;/p&gt;&#10;&lt;h3&gt;Challenge&lt;/h3&gt;&#10;&lt;p&gt;Have a look at the Python code below, then see if you can write the same program in Scratch.&lt;/p&gt;&#10;&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&#10;&lt;pre&gt;&lt;code&gt;&lt;span&gt;name&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;What is your name?&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Hello &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;name&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;&amp;quot;. It is nice to meet you&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;age&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;How old are you?&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;age&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;int&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;age&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;You were born in &amp;quot;&lt;/span&gt;&lt;span&gt;+&lt;/span&gt; &lt;span&gt;str&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt; &lt;span&gt;-&lt;/span&gt; &lt;span&gt;age&lt;/span&gt;&lt;span&gt;))&lt;/span&gt; &#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;Which parts of the program were easier to create in Python, and which parts were easier to create in Scratch?&lt;/p&gt;&#10;&lt;h3&gt;Challenge&lt;/h3&gt;&#10;&lt;p&gt;Have a look at the Scratch code below. Can you recreate it in Python?&lt;/p&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-19.png&quot; alt=&quot;1-6-19.png&quot;/&gt;&lt;/p&gt;&#10;&lt;h3&gt;A quick note on sharing&lt;/h3&gt;&#10;&lt;p&gt;We love it when our learners share their code in the comments, either to get some constructive feedback or when helping others. However, the comments section is designed for commenting, not for displaying formatted code like this.&lt;/p&gt;&#10;&lt;p&gt;If you want to share your Scratch scripts, then you can share the link to your code. Similarly, if you are using Trinket in the first few weeks of the course, then just create links to the code you want to share.&lt;/p&gt;&#10;&lt;p&gt;If you are using Python that has been installed on your computer, then the best way to share your code with others is through a sharing service. The one that most software developers use for simple code snippets is&lt;span&gt; &lt;/span&gt;&lt;a href=&quot;https://gist.github.com/&quot; rel=&quot;nofollow ugc noopener&quot;&gt;GitHub Gists&lt;/a&gt;. You can create an account, and then have as many private or public gists as you like. An even simpler solution is to use a pasting service such as&lt;span&gt; &lt;/span&gt;&lt;a href=&quot;https://pastebin.com/&quot; rel=&quot;nofollow ugc noopener&quot;&gt;Pastebin&lt;/a&gt;.&lt;/p&gt;&#10;&lt;br/&gt;&#10;&lt;br/&gt;&#10;&lt;br/&gt;&#10;</content>
<published>2018-06-29T19:49:48+03:00</published>
</entry>

<entry>
<title>ERILAISIA JUTTUJA :)</title>
<id>https://peda.net/id/1b559f4c7bb</id>
<updated>2018-06-29T19:41:40+03:00</updated>
<link href="https://peda.net/p/anu.salow%40posio.fi/kccmpp/lto/ej#top" />
<content type="html">SILLY STORY - HASSU KERTOMUS PYTHONILLA&lt;br/&gt;&#10;&lt;br/&gt;&#10;&lt;a href=&quot;https://www.futurelearn.com/courses/block-to-text-based-programming/2/steps/354639&quot; rel=&quot;nofollow ugc noopener&quot;&gt;https://www.futurelearn.com/courses/block-to-text-based-programming/2/steps/354639&lt;/a&gt;&lt;br/&gt;&#10;&lt;br/&gt;&#10;​&lt;div class=&quot;externalfile preview video&quot;&gt;&lt;video src=&quot;https://peda.net/p/anu.salow%40posio.fi/kccmpp/lto/ej/silly-story-mp4:file/download/7f63d5124bf147fa781879cbb1a962390fc7f62e/silly%20story.mp4&quot; controls=&quot;controls&quot; preload=&quot;metadata&quot;&gt;&#10;&lt;a href=&quot;https://peda.net/p/anu.salow%40posio.fi/kccmpp/lto/ej/silly-story-mp4:file/download/7f63d5124bf147fa781879cbb1a962390fc7f62e/silly%20story.mp4&quot;&gt;&lt;img src=&quot;https://peda.net/p/anu.salow%40posio.fi/kccmpp/lto/ej/silly-story-mp4:file/photo/7f63d5124bf147fa781879cbb1a962390fc7f62e/silly%20story.mp4&quot; alt=&quot;&quot; loading=&quot;lazy&quot;/&gt;&lt;/a&gt;&lt;/video&gt;&#10;&lt;/div&gt;&#10;​&lt;br/&gt;&#10;&lt;br/&gt;&#10;&lt;p&gt;You can use this passage for your game if you like, or come up with your own version. Now that we have the basic text, we can replace some of the words, such as nouns and verbs. Here’s an example.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;strong&gt;Ice cream is a frozen dessert made from&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;plural noun&lt;span&gt; &lt;/span&gt;&lt;strong&gt;,with added flavours and sweeteners. This mixture is quickly frozen while it is&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;verb ending in ed&lt;span&gt; &lt;/span&gt;&lt;strong&gt;,so that large&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;plural noun&lt;span&gt; &lt;/span&gt;&lt;strong&gt;do not form. Some ice cream is made with&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;noun&lt;span&gt; &lt;/span&gt;&lt;strong&gt;,extracted from seaweed, so that it is not sticky. There are many different flavours of ice cream, such as&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;food&lt;span&gt; &lt;/span&gt;&lt;strong&gt;and&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;food&lt;span&gt; &lt;/span&gt;&lt;strong&gt;. Ice cream often has things added to it for flavour, like&lt;/strong&gt;&lt;span&gt; &lt;/span&gt;noun, noun&lt;span&gt; &lt;/span&gt;&lt;strong&gt;, or&lt;/strong&gt;noun.&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;p&gt;Now let’s look at how you could use Python to create a Mad Libs–style game. The algorithm is fairly simple:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Ask for the user to input some words, such as plural nouns and foods&lt;/li&gt;&#10;&lt;li&gt;Assign these inputs to variables&lt;/li&gt;&#10;&lt;li&gt;Insert these variable values into the strings to complete the paragraph&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;!--filtered tag: &lt;h4--&gt;&lt;!--&amp;gt;--&gt;Step 1 and 2&lt;!--filtered end tag: &lt;/h4&gt;--&gt;&#10;&lt;p&gt;In Python, asking the user for input and assigning the value to a variable can be accomplished in a single line:&lt;/p&gt;&#10;&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&#10;&lt;pre&gt;&lt;code&gt;&lt;span&gt;answer&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;'What is the meaning of life? '&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;!--filtered tag: &lt;h4--&gt;&lt;!--&amp;gt;--&gt;Step 3&lt;!--filtered end tag: &lt;/h4&gt;--&gt;&#10;&lt;p&gt;You can then use this variable in a&lt;span&gt; &lt;/span&gt;&lt;code&gt;print&lt;/code&gt;&lt;span&gt; &lt;/span&gt;statement using simple string concatenation.&lt;/p&gt;&#10;&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&#10;&lt;pre&gt;&lt;code&gt;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;'The meaning of life is '&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;answer&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;'.'&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;So, to make the Mad Libs game, you can begin by asking the user for a load of words, and finish by inserting them into some strings that will be printed.&lt;/p&gt;&#10;&lt;p&gt;Here is the code for a complete Python program, and below that is a Trinket version for you to test out.&lt;/p&gt;&#10;&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&#10;&lt;pre&gt;&lt;code&gt;&lt;span&gt;noun_1&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me a plural noun &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;verb&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me a verb ending in ed &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;noun_2&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me another plural noun &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;noun_3&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me a noun &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;adjective&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me an adjective &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;food_1&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me a type of food &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;food_2&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me another type of food &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;noun_4&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me a noun &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;noun_5&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;and another one &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;noun_6&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; &lt;span&gt;input&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Give me one last noun &amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&#10;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Ice cream is a frozen dessert made from &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;noun_1&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;&amp;quot;, with added flavours and sweeteners&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;This mixture is quickly frozen while it is &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;verb&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;&amp;quot;, so that large &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;noun_2&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;&amp;quot; do not form.&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Some ice cream is made with &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;noun_3&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;&amp;quot; extracted from seaweed, so that it is not &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;adjective&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;There are many different flavours of ice cream, such as &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;food_1&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;&amp;quot; and &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;food_2&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;span&gt;print&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Ice cream often has things added to it for flavour, like &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;noun_4&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;&amp;quot;, &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;noun_5&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;&amp;quot; or &amp;quot;&lt;/span&gt; &lt;span&gt;+&lt;/span&gt; &lt;span&gt;noun_6&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;There are only three programming constructs used in the game:&lt;/p&gt;&#10;&lt;!--filtered tag: &lt;h4--&gt;&lt;!--&amp;gt;--&gt;1. Asking for input from the user and assigning variables to that input&lt;!--filtered end tag: &lt;/h4&gt;--&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-17.final.png&quot; alt=&quot;1-6-17&quot;/&gt;&lt;/p&gt;&#10;&lt;!--filtered tag: &lt;h4--&gt;&lt;!--&amp;gt;--&gt;2. Outputting strings&lt;!--filtered end tag: &lt;/h4&gt;--&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-3.final.png&quot; alt=&quot;1-6-3&quot;/&gt;&lt;/p&gt;&#10;&lt;!--filtered tag: &lt;h4--&gt;&lt;!--&amp;gt;--&gt;3. Concatenating strings&lt;!--filtered end tag: &lt;/h4&gt;--&gt;&#10;&lt;p&gt;&lt;img src=&quot;https://s3-eu-west-1.amazonaws.com/rpf-futurelearn/block-to-text/week1/images/1-6-15.final.png&quot; alt=&quot;1-6-15&quot;/&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Now see if you can recreate this program using Scratch.&lt;/strong&gt;&lt;/p&gt;&#10;&lt;p&gt;Ask for help in the comments if you become stuck, and once you have completed your program, you can share your creation by adding a link to the project.&lt;/p&gt;&#10;</content>
<published>2018-06-29T19:40:18+03:00</published>
</entry>


</feed>