<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog – Heaplevel AB</title>
	<atom:link href="https://heaplevel.com/category/blog/feed/" rel="self" type="application/rss+xml" />
	<link>https://heaplevel.com</link>
	<description>Software Development Partner</description>
	<lastBuildDate>Tue, 19 May 2026 06:34:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://heaplevel.com/wp-content/uploads/2020/01/cropped-Heaplevel-1-32x32.png</url>
	<title>Blog – Heaplevel AB</title>
	<link>https://heaplevel.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Python Dictionaries and While Loops for Beginners</title>
		<link>https://heaplevel.com/blog/python-data-structures-part-1-a-look-at-variables-and-lists/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Thu, 13 Mar 2025 18:21:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=416</guid>

					<description><![CDATA[<p>An introduction to datastructures in Python, this post takes a look at variables and introduces lists.</p>
<p>The post <a href="https://heaplevel.com/blog/python-data-structures-part-1-a-look-at-variables-and-lists/">Python Dictionaries and While Loops for Beginners</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<div id="outline-container-org20e7020" class="outline-2">
<h2 id="org20e7020">Introduction</h2>
<div class="outline-text-2" id="text-org20e7020">
<p> Welcome to the post about Python dictionaries in this series <i>Learn Python by Programming Fundamentals First</i>, where we practice programming fundamentals using the Python programming language. </p>
<p> In this post we will continue to work on the training app and build more functionality by utilizing Python dictionaries. </p>
<p> As you might have guessed, <i>dictionaries</i> are a fundamental part of most programming languages, therefore it&#8217;s important to learn how to use them efficiently. As you move on and learn new languages, e.g. Java or C++, the same concepts will apply. </p>
<p> Dictionaries belong to the category <i>fundamental data structures</i>, and are used whenever you want to manage pair-wise information, or a key-value format in programming terms. One example where this is used is in your phone. When you search for a contact, that name is linked to a phone number. We could say that the name has a direct relationship to the number. Whenever these relationships are necessary to represent in a program, a dictionary is usually a good starting point. </p>
<p> Finally, we will build on the concept of loops and look at <i>while loops</i> together with <i>functions</i> as well. <i>Functions</i> are part of a deeper topic that we&#8217;ll cover in upcoming posts. The exercises at the end should be a priority to do in order to practice what you&#8217;ve learned. </p>
<p> You can read more about dictionaries in the official Python docs at: <a href="https://docs.python.org/3/tutorial/datastructures.html">https://docs.python.org/3/tutorial/datastructures.html</a> </p>
</div>
</div>
<div id="outline-container-org3028bfd" class="outline-2">
<h2 id="org3028bfd">Purpose</h2>
<div class="outline-text-2" id="text-org3028bfd">
<p> The purpose of this article is to help you understand Python dictionaries, functions and  while loops and how to use them in your own programs. </p>
</div>
</div>
<div id="outline-container-orgf6775bb" class="outline-2">
<h2 id="orgf6775bb">Goal</h2>
<div class="outline-text-2" id="text-orgf6775bb">
<p> By the end of this post you will be able to </p>
<ul class="org-ul">
<li>Understand what a dictionary is</li>
<li>Create and modify dictionaries</li>
<li>Use the built-in dictionary methods, such as <code>.get()</code>, <code>.items()</code></li>
<li>Know when you should use a while loop</li>
</ul>
</div>
</div>
<div id="outline-container-orgda8445e" class="outline-2">
<h2 id="orgda8445e">Prerequisites</h2>
<div class="outline-text-2" id="text-orgda8445e">
<p> You must have Python installed and be able to start IDLE or your IDE to follow along. You should be familiar with how to create modules/script and run a Python script, either from the terminal or the GUI window. </p>
<p> A good starting point is this link: <a href="https://heaplevel.com/?p=337">How To Install Python On Your Computer</a> </p>
<p> Additionally you should have finished <a href="https://heaplevel.com/?p=393">Python and the Building Blocks of Programming</a> and <a href="https://heaplevel.com/?p=450">Python if-statements and loops &#8211; how to be lazy</a> </p>
<p> If you found anything difficult in previous posts, don&#8217;t hesitate to let us know! <a href="https://heaplevel.com/?p=30">Contact Us</a> </p>
</div>
</div>
<div id="outline-container-orga443cf5" class="outline-2">
<h2 id="orga443cf5">Try It Yourself: Python Dictionary Example</h2>
<div class="outline-text-2" id="text-orga443cf5">
<p> Look at the following code, copy and paste it into your IDE of choice, e.g. IDLE or PyCharm. If you run the program, what do you expect to see? Think about it and compare it with the output. </p>
<div class="org-src-container">
<label class="org-src-name"><em> Name: dictionary1.py.</em></label></p>
<pre class="src src-python" id="dictionary1.py"><span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">A simple dictionary with some fruits and their colors</span>
<span style="color: #4ac964;">fruit_colors</span> = {
    <span style="color: #ff7fff;">"apple"</span>: <span style="color: #ff7fff;">"red"</span>,
    <span style="color: #ff7fff;">"banana"</span>: <span style="color: #ff7fff;">"yellow"</span>,
    <span style="color: #ff7fff;">"grape"</span>: <span style="color: #ff7fff;">"purple"</span>
}

<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Accessing a value</span>
<span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"The color of an apple is:"</span>, fruit_colors[<span style="color: #ff7fff;">"apple"</span>])

<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Adding a new key-value pair</span>
<span style="color: #4ac964;">fruit_colors</span>[<span style="color: #ff7fff;">"orange"</span>] = <span style="color: #ff7fff;">"orange"</span>

<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Updating a value</span>
<span style="color: #4ac964;">fruit_colors</span>[<span style="color: #ff7fff;">"banana"</span>] = <span style="color: #ff7fff;">"green"</span>

<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Deleting a key-value pair</span>
<span style="color: #ffff0b;">del</span> fruit_colors[<span style="color: #ff7fff;">"grape"</span>]

<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Looping through the dictionary</span>
<span style="color: #ffff0b;">for</span> fruit, color <span style="color: #ffff0b;">in</span> fruit_colors.items():
    <span style="color: #ff9029;">print</span>(f<span style="color: #ff7fff;">"</span>{fruit.title()}<span style="color: #ff7fff;"> is </span>{color}<span style="color: #ff7fff;">."</span>)

</pre>
</div>
</div>
<div id="outline-container-org66699f7" class="outline-3">
<h3 id="org66699f7">Dictionary Concept Breakdown / Code Analysis</h3>
<div class="outline-text-3" id="text-org66699f7">
<p> Let&#8217;s start by inspecting the new syntax. The dictionary definition for <code>fruit_colors</code> starts with curly braces ( {} ), and it&#8217;s stored in the variable <code>fruit_colors</code>. Notice the format for defining a dictionary is <code>"key":"value"</code>. </p>
<p> The result is a dictionary that contains three keys: <code>apple, banana, grape</code> and three values <code>red, yellow, purple</code>. These are the three pairs in the dictionary: apple+red, banana+yellow and grape+purple. </p>
<p> You can use square brackets <code>[]</code> in order to access a key in the dictionary, which is used in the print-statement. Python also has a built-in method <code>.get()</code> that can be used to retrieve a key&#8217;s value. </p>
<p> Finally, in the for-loop we use the dictionary method <code>.items()</code> to access the key and value at the same time. In each iteration, the variables <code>fruit</code> and <code>color</code> are assigned from the dictionary <code>fruit_colors</code>. </p>
</div>
</div>
</div>
<div id="outline-container-org40adbe5" class="outline-2">
<h2 id="org40adbe5">Project – Workout App Exercise Details</h2>
<div class="outline-text-2" id="text-org40adbe5">
<p> Now using this new concept, let&#8217;s get back to our project again and see if there&#8217;s any good use case for a dictionary. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #4ac964;">week</span> = 1
<span style="color: #4ac964;">schedule</span> = <span style="color: #ff7fff;">'Workout A'</span>
<span style="color: #4ac964;">exercises</span> = (<span style="color: #ff7fff;">'Bench press'</span>, <span style="color: #ff7fff;">'Deadlift'</span>, <span style="color: #ff7fff;">'Squat'</span>, <span style="color: #ff7fff;">'Biceps curl'</span>)

<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">New code for dictionaries here soon</span>
<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">...</span>
<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">...</span>

<span style="color: #4ac964;">response</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">'Would you like to see all exercises in the training schedule? (Yes/No) '</span>)

<span style="color: #4ac964;">selected_exercise</span> = <span style="color: #34c8d8;">None</span>
<span style="color: #ffff0b;">if</span> response == <span style="color: #ff7fff;">'Yes'</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Here are all the exercises:'</span>)
<span style="color: #ffff0b;">elif</span> response == <span style="color: #ff7fff;">'No'</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Okay, we won&#8217;t show any exercises right now.'</span>)
<span style="color: #ffff0b;">else</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Invalid response, please type "Yes" or "No".'</span>)

    <span style="color: #4ac964;">selected_exercise</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">'Which exercise would you like to know more about? '</span>)

<span style="color: #ffff0b;">if</span> selected_exercise <span style="color: #ffff0b;">in</span> exercises:
    <span style="color: #ff9029;">print</span>(f<span style="color: #ff7fff;">'You chose </span>{selected_exercise}<span style="color: #ff7fff;">. This is a fundamental exercise for building strength.'</span>)
<span style="color: #ffff0b;">else</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'That exercise is not in the schedule.'</span>)


</pre>
</div>
<p> Next we will implement the idea to include a description for each exercise. It&#8217;s easy to extend the program and provide more information about an exercise if necessary. For example, to add a video link on how to perform an exercise, you could store that info in a dictionary as well. </p>
<p> In order to put this idea into code, let&#8217;s create a new variable called <code>exercise_details</code> that will (you guessed right) hold the description associated with an exercise. Here&#8217;s a suggestion, you may change the description text yourself. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #4ac964;">exercise_details</span> = {
    <span style="color: #ff7fff;">"Bench press"</span>: <span style="color: #ff7fff;">"Compound exercise for upper body"</span>,
    <span style="color: #ff7fff;">"Deadlift"</span>: <span style="color: #ff7fff;">"Compound exercise for lower body and core"</span>,
    <span style="color: #ff7fff;">"Squat"</span>: <span style="color: #ff7fff;">"King of exercises, compound and overall legs"</span>,
    <span style="color: #ff7fff;">"Biceps curl"</span>: <span style="color: #ff7fff;">"Isolation exercise for the upper arms"</span>
}
</pre>
</div>
<p> Now we can use two Python built-in methods to query the dictionary. You&#8217;ve already seen <code>items()</code> above, Python also provides <code>.keys()</code> and <code>.values()</code> for returning <i>view objects</i> of keys and values respectively. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ff9029;">print</span>(exercises)
<span style="color: #ff9029;">print</span>(exercise_details.keys())
<span style="color: #ff9029;">print</span>(exercise_details.values())
</pre>
</div>
<p> Output </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil">(<span style="color: #ff7fff;">'Bench press'</span>, <span style="color: #ff7fff;">'Deadlift'</span>, <span style="color: #ff7fff;">'Squat'</span>, <span style="color: #ff7fff;">'Biceps curl'</span>)
dict_keys([<span style="color: #ff7fff;">'Bench press'</span>, <span style="color: #ff7fff;">'Deadlift'</span>, <span style="color: #ff7fff;">'Squat'</span>, <span style="color: #ff7fff;">'Biceps curl'</span>])
dict_values([<span style="color: #ff7fff;">'Compound exercise for upper body'</span>, <span style="color: #ff7fff;">'Compound exercise for lower body and core'</span>,
               <span style="color: #ff7fff;">'King of exercises, compound and overall legs'</span>, <span style="color: #ff7fff;">'Isolation exercise for the upper arms'</span>])
</pre>
</div>
<p> You might have noticed the output of  <code>exercises</code> and calling <code>.keys()</code> on the dictionary are rather similar. Remember that <code>exercises</code> is a declared variable that holds a <i>tuple</i>. It&#8217;s related to the <code>exercise_details</code> keys by design from the programmer (us). However, the tuple is a different data structure from the <i>view object</i> returned by <code>.keys()</code> </p>
<p> The view object is a dynamic representation of the keys in a dictionary, meaning it always reflects the current state of the dictionary. A tuple however, is <i>immutable</i>, meaning it cannot be changed after it was created. </p>
</div>
</div>
<div id="outline-container-org3313895" class="outline-2">
<h2 id="org3313895">While Loop &#8211; The For-loop&#8217;s cousin</h2>
<div class="outline-text-2" id="text-org3313895">
<p> The purpose of a while loop is to repeat a code block until a condition is met. This is also called <i>iteration</i> in programming terms. Both the while and for loops are used frequently. Eventually you&#8217;ll develop an intuition on when to use them. </p>
<p> The program has to handle errors when users enter information into the program. </p>
<p> If you run the program and press Enter at the first question, the program will continue to the next question without any error control. That is not ideal. </p>
<p> In our program, the idea is not to proceed to the next question, until a valid choice has been made by the user. Therefore we want to <i>repeat</i> any question or choice prompted to the user. </p>
<p> A <code>while</code> loop can repeat a code block until a condition is met. That&#8217;s the idea we will implement next in our program. </p>
<p> &#8220;&#8221;&#8221; Until the user has left a valid choice, repeat the code block &#8220;&#8221;&#8221; </p>
<p> Let&#8217;s first take a look at the anatomy of a while loop. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ffff0b;">while</span> boolean-expression:
    code block
    ...etc
</pre>
</div>
<p> This will run the code block repeatedly as long as the boolean expression is True. A <i>boolean</i> expression is an expression that evaluates to either <code>True</code> or <code>False</code>. </p>
<p> Notice the indentation of the <i>code block</i>. It is also possible to use a <i>break</i> statement inside the code block in order to stop the while loop, we will cover an example of this below. </p>
<p> Here&#8217;s another example of a <code>while</code> loop that repeatedly prints <code>Hello</code> to the console, don&#8217;t run this program (yet). </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ffff0b;">while</span> <span style="color: #34c8d8;">True</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Hello"</span>)
</pre>
</div>
<p> The word <i>Hello</i> is printed after the first iteration, then the program will start the next iteration, and determine that the condition is still <code>True</code>. Therefore, the program enters the code block again. The code block that prints <i>Hello</i> is executed again, then the next iteration starts and the program repeats this process infinitely. </p>
<p> Workflow of the program: </p>
<p><em></em></p>
<pre class="example" id="nil">
1. while True mean "yes let's enter the code block"
2. print Hello
3. Go back to step 1) and evaluate whether the expression is True (which it is)
4. print Hello

</pre>
<p> In contrast to the <i>if statement</i>, we need a mechanism to break out of this loop. The way to handle this is to simply add a <code>break</code> statement in order to exit the loop. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ffff0b;">while</span> <span style="color: #34c8d8;">True</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Hello"</span>)
    <span style="color: #ffff0b;">break</span> <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Don't remove this</span>
</pre>
</div>
<p> Now our program will print the word <i>Hello</i> once and immediately finish and exit the loop. If you were to remove that <code>break</code> statement as in the first version, the program would continue to print forever, and you&#8217;d have to kill the program somehow, probably by entering <i>Ctrl-C</i> or closing the IDE. </p>
<p> With this in mind, it&#8217;s important to construct a <code>while</code> loop such that it doesn&#8217;t result in an infinite loop as it&#8217;s called. It takes a little practice, but it&#8217;s nothing to worry about as continue to improve your understanding of programming loops. </p>
<p> Another common use case of a <code>while</code> is during counting. Here&#8217;s what that looks like </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #4ac964;">counter</span> = 0
<span style="color: #ffff0b;">while</span> counter &lt; 10:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Counter is at "</span>, counter)
    <span style="color: #4ac964;">counter</span> = counter + 1 <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Increment the counter in every loop</span>
</pre>
</div>
<p> This doesn&#8217;t result in an infinite loop because the counter increases during every iteration. Eventually, it will reach a number that&#8217;s greater than 10, thereby evaluating the boolean expression to False. Run the program and see if you can understand how it works. </p>
</div>
<div id="outline-container-orgb19f083" class="outline-3">
<h3 id="orgb19f083">Before you move on</h3>
<div class="outline-text-3" id="text-orgb19f083">
<blockquote>
<p> Experiment and see what changes when the condition is set to 15 instead of 10. If you switch the condition to greater than instead, i.e <code>counter &gt; 10</code> &#8211; what do you notice? </p>
</blockquote>
<p> Let&#8217;s look at a final example before implementing this in our own program. </p>
<p> Here&#8217;s a similar construct to the previous example, but the idea is still to use a break statement to exit the loop. </p>
<p> At first sight, it might look like an infinite loop, but because an exit condition exists, it&#8217;s possible for the program to eventually exit, when the user types <code>Quit</code> into the program. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Almost an infinite loop. It keeps running until the user type Quit however.</span>
<span style="color: #ffff0b;">while</span> <span style="color: #34c8d8;">True</span>:
    <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Ask the user for input</span>
    <span style="color: #4ac964;">answer</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">"If you want to quit this loop, please type Quit "</span>)

    <span style="color: #ffff0b;">if</span> answer == <span style="color: #ff7fff;">"Quit"</span>:
          <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Breaking out the loop...see you next time"</span>)
          <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Special keyword to exit the loop</span>
          <span style="color: #ffff0b;">break</span>
    <span style="color: #ffff0b;">else</span>:
          <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Ok, so you dont want to quit...trying another turn"</span>)
</pre>
</div>
<p> In the above example, the <code>break</code> statement is placed after a conditional statement (if), it&#8217;s not necessary to place it at the beginning of the loop. It&#8217;s up to the programmer to decide under which conditions the loop should break. </p>
<p> Finally, the construct of <code>while True</code> is very common in menu systems and when a program waits for user input. </p>
</div>
</div>
<div id="outline-container-org0400ef4" class="outline-3">
<h3 id="org0400ef4">While Loop Concept Breakdown / Code Analysis</h3>
<div class="outline-text-3" id="text-org0400ef4">
<p> Let&#8217;s repeat what we&#8217;ve covered so far. </p>
<p> A <code>while</code> loop consists of a condition and a code block. The loop executes the code block as long as the <i>boolean expression</i> evaluates to true. </p>
<p> We saw that a <code>while True:</code> loop repeats a code block forever, the only way to break out of the loop is to execute a <code>break</code> statement somewhere inside the code block. Where and how this is done is up to the programmer. In the previous example this happens when the user enters <code>Quit</code>. </p>
<p> In contrast, <code>while False:</code> would not be useful as the program would never enter the loop, and just skip to the next statements of the program. </p>
<p> Run the examples until you start to understand how they work. If you get stuck, feel free to reach out at -&gt;  <a href="https://heaplevel.com/?p=30">Contact Us</a> </p>
</div>
</div>
</div>
<div id="outline-container-orgc15642e" class="outline-2">
<h2 id="orgc15642e">Project continued &#8211; While Loop</h2>
<div class="outline-text-2" id="text-orgc15642e">
<p> Back to our training app project, let&#8217;s focus on the first parts of the code. If you remember, we want to validate the answer from the user before moving on. </p>
<p> Therefore, we&#8217;ll wrap our first question inside a <code>while True:</code> loop instead of continuing when user enters something invalid. We can also improve the check with the operator <code>in</code> as we saw in the previous <a href="https://heaplevel.com/?p=450">post</a> on the <code>in</code> operator. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ffff0b;">while</span> <span style="color: #34c8d8;">True</span>:
    <span style="color: #4ac964;">response</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">'Would you like to see all exercises in the training schedule? (Yes/No) '</span>)

    <span style="color: #ffff0b;">if</span> response <span style="color: #ffff0b;">in</span> (<span style="color: #ff7fff;">"Yes"</span>, <span style="color: #ff7fff;">"yes"</span>):
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Here are all the exercises:"</span>)
        <span style="color: #ffff0b;">for</span> item <span style="color: #ffff0b;">in</span> exercises:
            <span style="color: #ff9029;">print</span>(item)
        <span style="color: #ffff0b;">break</span> <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Break out of the loop, we don't want to repeat the question anymore</span>
    <span style="color: #ffff0b;">elif</span> response <span style="color: #ffff0b;">in</span> (<span style="color: #ff7fff;">"No"</span>, <span style="color: #ff7fff;">"no"</span>):
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Cool, no hard feelings!"</span>)
        <span style="color: #ffff0b;">break</span>
    <span style="color: #ffff0b;">else</span>:
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"You must answer Yes/No, please try again"</span>)
</pre>
</div>
<p> This looks much better. However, we should also notice that after running this program, in the case the user enters <i>No</i> it would be incorrect and weird to continue to the second question. So we&#8217;ll have to fix next. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #4ac964;">answered_yes</span> = <span style="color: #34c8d8;">False</span> <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Add a new variable</span>
<span style="color: #ffff0b;">while</span> <span style="color: #34c8d8;">True</span>:
    <span style="color: #4ac964;">response</span> = <span style="color: #ff9029;">input</span>(
        <span style="color: #ff7fff;">"Would you like to see all exercises in the training schedule? (Yes/No) "</span>
    )

    <span style="color: #ffff0b;">if</span> response <span style="color: #ffff0b;">in</span> (<span style="color: #ff7fff;">"Yes"</span>, <span style="color: #ff7fff;">"yes"</span>): <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Check membership in the tuple</span>
        <span style="color: #4ac964;">answered_yes</span> = <span style="color: #34c8d8;">True</span> <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Store the user's choice</span>
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Here are all the exercises:"</span>)
        <span style="color: #ffff0b;">for</span> item <span style="color: #ffff0b;">in</span> exercises:
            <span style="color: #ff9029;">print</span>(item)
        <span style="color: #ffff0b;">break</span>
    <span style="color: #ffff0b;">elif</span> response <span style="color: #ffff0b;">in</span> (<span style="color: #ff7fff;">"No"</span>, <span style="color: #ff7fff;">"no"</span>):
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Cool, no hard feelings!"</span>)
        <span style="color: #ffff0b;">break</span>
    <span style="color: #ffff0b;">else</span>:
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"You must answer Yes/No, please try again"</span>)

<span style="color: #ffff0b;">if</span> answered_yes: 
    <span style="color: #4ac964;">selected_exercise</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">"Which exercise would you like to know more about? "</span>)

    <span style="color: #ffff0b;">if</span> selected_exercise <span style="color: #ffff0b;">in</span> exercises:
        <span style="color: #ff9029;">print</span>(
            f<span style="color: #ff7fff;">"You chose </span>{selected_exercise}<span style="color: #ff7fff;">. This is a fundamental exercise for building strength."</span>
        )
    <span style="color: #ffff0b;">else</span>:
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"That exercise is not in the schedule."</span>)


</pre>
</div>
<p> We introduce a new variable called <code>answered_yes</code> that is set to <code>True</code> in the same code block where we print all the exercises, because that&#8217;s when we know the answer from the user is <i>Yes</i>. This is also called a state variable, or sometimes a flag variable and it comes in handy when a program must deal with control flow during execution. </p>
<p> Later in the program, we use an <code>if</code> statement to check the value of the state variable, and only if its value is <code>True</code> do we print the second question. </p>
<p> At this stage, we have fair amount of code in our program that works well. We have a small interactive Python program using loops, conditionals, tuples, and dictionaries, not a small feat! </p>
<p> Here&#8217;s the complete Python program so far, go ahead and run it in your own IDE. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #4ac964;">week</span> = 1
<span style="color: #4ac964;">schedule</span> = <span style="color: #ff7fff;">"Workout A"</span>
<span style="color: #4ac964;">exercises</span> = (<span style="color: #ff7fff;">"Bench press"</span>, <span style="color: #ff7fff;">"Deadlift"</span>, <span style="color: #ff7fff;">"Squat"</span>, <span style="color: #ff7fff;">"Biceps curl"</span>)

<span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Unused variable for now</span>
<span style="color: #4ac964;">exercise_details</span> = {
    <span style="color: #ff7fff;">"Bench press"</span>: <span style="color: #ff7fff;">"Compound exercise for upper body"</span>,
    <span style="color: #ff7fff;">"Deadlift"</span>: <span style="color: #ff7fff;">"Compound exercise for lower body and core"</span>,
    <span style="color: #ff7fff;">"Squat"</span>: <span style="color: #ff7fff;">"King of exercises, compound and overall legs"</span>,
    <span style="color: #ff7fff;">"Biceps curl"</span>: <span style="color: #ff7fff;">"Isolation exercise for the upper arms"</span>,
}


<span style="color: #4ac964;">answered_yes</span> = <span style="color: #34c8d8;">False</span>
<span style="color: #ffff0b;">while</span> <span style="color: #34c8d8;">True</span>:
    <span style="color: #4ac964;">response</span> = <span style="color: #ff9029;">input</span>(
        <span style="color: #ff7fff;">"Would you like to see all exercises in the training schedule? (Yes/No) "</span>
    )

    <span style="color: #ffff0b;">if</span> response <span style="color: #ffff0b;">in</span> (<span style="color: #ff7fff;">"Yes"</span>, <span style="color: #ff7fff;">"yes"</span>):
        <span style="color: #4ac964;">answered_yes</span> = <span style="color: #34c8d8;">True</span>
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Here are all the exercises:"</span>)
        <span style="color: #ffff0b;">for</span> item <span style="color: #ffff0b;">in</span> exercises:
            <span style="color: #ff9029;">print</span>(item)
        <span style="color: #ffff0b;">break</span>  <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Break out of the loop, we don't want to repeat the question anymore</span>
    <span style="color: #ffff0b;">elif</span> response <span style="color: #ffff0b;">in</span> (<span style="color: #ff7fff;">"No"</span>, <span style="color: #ff7fff;">"no"</span>):
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Cool, no hard feelings!"</span>)
        <span style="color: #ffff0b;">break</span>
    <span style="color: #ffff0b;">else</span>:
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"You must answer Yes/No, please try again"</span>)

<span style="color: #ffff0b;">if</span> answered_yes:
    <span style="color: #4ac964;">selected_exercise</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">"Which exercise would you like to know more about? "</span>)

    <span style="color: #ffff0b;">if</span> selected_exercise <span style="color: #ffff0b;">in</span> exercises:
        <span style="color: #ff9029;">print</span>(
            f<span style="color: #ff7fff;">"You chose </span>{exercises[selected_exercise]}<span style="color: #ff7fff;">. This is a fundamental exercise for building strength.</span>
<span style="color: #ff7fff;">            </span>{exercise_details[selected_exercise]}<span style="color: #ff7fff;">.</span>
<span style="color: #ff7fff;">            "</span>
        )
    <span style="color: #ffff0b;">else</span>:
        <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"That exercise is not in the schedule."</span>)

</pre>
</div>
</div>
</div>
<div id="outline-container-org6cf31ef" class="outline-2">
<h2 id="org6cf31ef">Exercises</h2>
<div class="outline-text-2" id="text-org6cf31ef">
<p> Here are some exercises to try on your own, you can try to building upon the program however you like. </p>
<ol class="org-ol">
<li>Create a new <i>dictionary</i> with your own keys and values. The dictionary should contain key-value pairs for countries and capitals. Create a second dictionary that stores name and age pairs. Print the dictionaries.</li>
<li>Retrieve a value from your dictionaries using a key and the <code>[]</code> notation. What happens if you specify a non-existent key or make a typo?</li>
<li>Add and update a values in your dictionaries</li>
<li>Add a new key-value pair using the bracket syntax: <code>your_dictionary[key] = value</code></li>
<li>Update an existing value using the bracket syntax. How is this different from accessing a key with a typo?</li>
<li>Remove an item using <code>del</code> and <code>.pop()</code>.</li>
<li>Use a for loop to print all keys in your dictionaries.</li>
<li>Ask the user for a key and check whether it exists in the dictionary.</li>
<li>Write a code block that swaps the keys and values. Remember you can use <code>.keys()</code> and <code>.values()</code>.</li>
<li>Use the method <code>.items()</code> on the <code>exercise_details</code> variable. You can decide where in the code to place it and print the contents.</li>
<li>Inside the <code>if selected_exercise in exercises:</code> use another <code>print</code> to print and fetch the value from <code>exercise_details</code> using <code>.get()</code>.</li>
<li>Add a third <code>print</code> to print the details, but this time using the <code>[]</code> notation.</li>
<li>Add another alternative to also accept the word &#8220;quit&#8221;.</li>
<li>Search the Python documentation for string methods, see if you can find a way to remove whitespace from the input string before checking it. So the program should also accept accidental spaces, like &#8220;quit &#8220;, &#8221;  Quit&#8221;. It&#8217;s enough to handle spaces around the word. <a href="https://docs.python.org/3/library/stdtypes.html#string-methods">https://docs.python.org/3/library/stdtypes.html#string-methods</a></li>
</ol>
</div>
</div>
<div id="outline-container-orgd9e3058" class="outline-2">
<h2 id="orgd9e3058">Summary</h2>
<div class="outline-text-2" id="text-orgd9e3058">
<p> In this section, we explored two important Pythoon programming concepts: dictionaries and while loops. These concepts are fundamental building blocks used in many real-world Python programs. </p>
<p> We have also covered Python dictionary <b>methods</b> and learned how dictionaries can be used to store and organize data inside a program. </p>
<p> We have also explored a simplified yet common process for how a program can be developed. We started with an introductory text and expanded it step by step by asking the user a question. We also printed the user’s response. </p>
<p> It’s not easy to build everything at once, we allowed the program details to grow naturally and also handled the control flow of the program better in small improvements. It’s good to think of this process as normal. </p>
<p> In the next section, we&#8217;ll continue working with Python control flow and how to write our own <i>functions</i>. Functions are used to break down a program into logical components, and helps us write program that consist of smaller building blocks. We&#8217;ll also look into how we can handle text files in Python. </p>
<p> Think about how you want to develop the Training App further. For example, you could let the user enter their own exercise descriptions or store workout history. The sky is the limit! </p>
<p> See you in the next post! </p>
</div>
</div><p>The post <a href="https://heaplevel.com/blog/python-data-structures-part-1-a-look-at-variables-and-lists/">Python Dictionaries and While Loops for Beginners</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Introducing a new Krita Plugin &#8211; Buttonz Booster</title>
		<link>https://heaplevel.com/news/introducing-a-new-krita-plugin-buttonz-booster/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Sun, 16 Feb 2025 13:54:26 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=435</guid>

					<description><![CDATA[<p>Krita has been my go-to application for digital drawing and editing. It&#8217;s a powerful open-source painting program, on par with professional software like Photoshop, and loved by artists worldwide Where does Buttonz Booster fit in? The purpose is to save you some clicks, and it allows you to create a new document with a predefined &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/news/introducing-a-new-krita-plugin-buttonz-booster/" class="more-link">Continue reading<span class="screen-reader-text"> "Introducing a new Krita Plugin &#8211; Buttonz Booster"</span></a></p>
<p>The post <a href="https://heaplevel.com/news/introducing-a-new-krita-plugin-buttonz-booster/">Introducing a new Krita Plugin – Buttonz Booster</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">Krita has been my go-to application for digital drawing and editing. It&#8217;s a powerful open-source painting program, on par with professional software like Photoshop, and loved by artists worldwide</p>



<p class="wp-block-paragraph">Where does <strong>Buttonz Booster</strong> fit in? </p>



<p class="wp-block-paragraph">The purpose is to save you some clicks, and it allows you to create a new document with a predefined size, simple and easy.</p>



<p class="wp-block-paragraph">You can install it directly from Krita, first download the ZIP file</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:100%">
<div class="wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-4fc3f8e1 wp-block-group-is-layout-flex">
<details class="wp-block-details is-layout-flow wp-block-details-is-layout-flow"><summary>Buttonz Booster</summary>
<div class="wp-block-file"><a id="wp-block-file--media-a2f97732-85c0-46a1-8326-1c835edd9f21" href="https://heaplevel.com/wp-content/uploads/2025/02/buttonbooztplugin.zip">buttonbooztplugin</a><a href="https://heaplevel.com/wp-content/uploads/2025/02/buttonbooztplugin.zip" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-a2f97732-85c0-46a1-8326-1c835edd9f21">Download</a></div>
</details>
</div>
</div>
</div>
</div></div>



<p class="wp-block-paragraph"><strong>Alt. download link</strong><br><a href="https://www.dropbox.com/scl/fi/hp12hct3n3rgvhys00iwy/buttonbooztplugin.zip?rlkey=5c0wzkp8u5erjjx6pty9hs50v&amp;st=xm243ii2&amp;dl=0">Alternative download link</a></p>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">How to Install</h2>



<ol class="wp-block-list">
<li>Go to menu Tools-&gt;Scripts-&gt;Import Python Plugin from File…¨</li>



<li>Locate the ZIP file you just downloaded. The install should prompt if everything went OK or not.</li>



<li>Restart Krita if all went fine.</li>



<li>Activate Settings-&gt;Docker-&gt;Buttonz Booster</li>
</ol>



<p class="wp-block-paragraph">I’m happy to share it with you all, and are there any quick actions you’d like to add? Let me know!</p><p>The post <a href="https://heaplevel.com/news/introducing-a-new-krita-plugin-buttonz-booster/">Introducing a new Krita Plugin – Buttonz Booster</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Python If Statements and Loops (Lazy Beginner Tutorial)</title>
		<link>https://heaplevel.com/blog/python-if-statements-and-loops/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Mon, 13 Jan 2025 07:49:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=450</guid>

					<description><![CDATA[<p>Welcome to the beginning parts of Learn Python In A Normal Way. In this series we&#8217;re working on our own Training App. The series focuses on how to get up and running with logical thinking and programming with Python, and it should suit the beginner since doing assignments is what makes you learn quicker. Make &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/blog/python-if-statements-and-loops/" class="more-link">Continue reading<span class="screen-reader-text"> "Python If Statements and Loops (Lazy Beginner Tutorial)"</span></a></p>
<p>The post <a href="https://heaplevel.com/blog/python-if-statements-and-loops/">Python If Statements and Loops (Lazy Beginner Tutorial)</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<p> Welcome to the beginning parts of Learn Python In A Normal Way. In this series we&#8217;re working on our own Training App. The series focuses on how to get up and running with logical thinking and programming with Python, and it should suit the beginner since doing assignments is what makes you learn quicker. </p>
<p> Make sure you&#8217;ve read the previous part <a href="https://heaplevel.com/?p=416">Python data structures part 1 &#8211; a look at variables and lists</a> </p>
<div id="outline-container-orgdc84df1" class="outline-2">
<h2 id="orgdc84df1">Why It Matters (Purpose)</h2>
<div class="outline-text-2" id="text-orgdc84df1">
<p> The purpose of this lesson is to cover Python if statements and loops. Writing a program is usually about making decisions based on different conditions. Changing path of execution in a program is done using if statements. Programs also store information and interact with users. During these interactions, you often need a menu system or a conversational flow. This is where loops come into play. </p>
</div>
</div>
<div id="outline-container-orgb6706eb" class="outline-2">
<h2 id="orgb6706eb">What You Will Learn (Goal)</h2>
<div class="outline-text-2" id="text-orgb6706eb">
<p> By the end of this post you can </p>
<ul class="org-ul">
<li>write and understand a Python if statement</li>
<li>write and understand a Python for loop in a simple scenario</li>
<li>write and understand how to Python boolean expressions</li>
</ul>
</div>
</div>
<div id="outline-container-org7460df4" class="outline-2">
<h2 id="org7460df4">Prerequisites</h2>
<div class="outline-text-2" id="text-org7460df4">
<p> You must have Python installed and be able to start IDLE to follow along. You should be familiar with how to create modules/script and run a Python script, either from the terminal or the GUI window. </p>
<p> A good starting point is this link: <a href="https://heaplevel.com/?p=337">How To Install Python On Your Computer</a> </p>
<p> Additionally you should have finished <a href="https://heaplevel.com/?p=416">Python data structures part 1 &#8211; a look at variables and lists</a> </p>
<p> If you found anything difficult in that part, please let us know! <a href="https://heaplevel.com/?p=30">Contact Us</a> </p>
</div>
</div>
<div id="outline-container-orga7d4704" class="outline-2">
<h2 id="orga7d4704">Python If Statement &#8211; make a choice in your application</h2>
<div class="outline-text-2" id="text-orga7d4704">
<p> A Python if statement gives you more control over a program. With an <code>if</code>-statement, we use the information of a variable to make a decision in your program. For example, if you want to display all exercises when the user responds &#8220;Yes,&#8221; and show a different message if the user responds &#8220;No,&#8221; you can use an <code>if</code>-statement. </p>
<p> Let&#8217;s see what they look like! </p>
</div>
<div id="outline-container-org0264fc2" class="outline-3">
<h3 id="org0264fc2">Code Block to Copy</h3>
<div class="outline-text-3" id="text-org0264fc2">
<p> Try the following code in a new script, which we’ll call <code>workout_v2.py</code>: </p>
<div class="org-src-container">
<label class="org-src-name"><em> Name: workout_v2.py.</em></label></p>
<pre class="src src-python" id="workout_v2.py"><span style="color: #4ac964;">week</span> = 1
<span style="color: #4ac964;">schedule</span> = <span style="color: #ff7fff;">'Workout A'</span>
<span style="color: #4ac964;">exercises</span> = (<span style="color: #ff7fff;">'Bench press'</span>, <span style="color: #ff7fff;">'Deadlift'</span>, <span style="color: #ff7fff;">'Squat'</span>, <span style="color: #ff7fff;">'Biceps curl'</span>)

<span style="color: #4ac964;">response</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">'Would you like to see all exercises in the training schedule? (Yes/No) '</span>)

<span style="color: #ffff0b;">if</span> response == <span style="color: #ff7fff;">'Yes'</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Here are all the exercises:'</span>)
    <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">more code here ...</span>
<span style="color: #ffff0b;">elif</span> response == <span style="color: #ff7fff;">'No'</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Okay, we won&#8217;t show any exercises right now.'</span>)
<span style="color: #ffff0b;">else</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Invalid response, please type "Yes" or "No".'</span>)
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org78262b7" class="outline-2">
<h2 id="org78262b7">Python If Statement Analysis</h2>
<div class="outline-text-2" id="text-org78262b7">
<p> The if statement in previous listing highlights three branches: </p>
<ol class="org-ol">
<li><b>Condition with <code>if</code></b>: If the user types &#8220;Yes,&#8221; the code block following the <code>if</code> statement is executed. We call this the first conditional block. The boolean expression (response == &#8216;Yes&#8217;) evaluates to either True or False, depending on what the user typed.</li>
<li><b>Alternative with <code>elif</code></b>: If the user types &#8220;No,&#8221; a different message is displayed.</li>
<li><b>Invalid response</b>: If the response is something other than &#8220;Yes&#8221; or &#8220;No,&#8221; the program shows a message explaining that only those answers are valid.</li>
</ol>
<p> It&#8217;s plain English, yet so important to get it right with Python syntax and indentation. Notice the colon, and the indentation for each block. Otherwise you will get a syntax error when you try to run the program. </p>
<p> Run the code and try typing &#8220;Yes,&#8221; &#8220;No,&#8221; and an invalid response (like &#8220;Maybe&#8221;) to see what happens. You’ll notice that the program becomes more interactive and adapts to the user’s input now. Pretty neat, right? </p>
</div>
</div>
<div id="outline-container-org23ca51c" class="outline-2">
<h2 id="org23ca51c">A note about conditional logic</h2>
<div class="outline-text-2" id="text-org23ca51c">
<p> When we write an if-statement, the <i>code block or the branch</i> to enter is evaluated according to a <i>boolean expression</i>. It&#8217;s the same as asking a Yes/No question, but in the computer world we call this True/False result. </p>
<p> The if-statement anatomy consists of the conditional block and the boolean expression </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ffff0b;">if</span> <span style="color: #34c8d8;">True</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"This will always be printed"</span>)
</pre>
</div>
<p> When we compared the user&#8217;s answer of &#8220;Yes&#8221; or &#8220;No&#8221;, the result of that comparison would either be True or False internally. </p>
<p> On the other hand, if we&#8217;d write </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ffff0b;">if</span> <span style="color: #34c8d8;">False</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"This will never be printed"</span>)
</pre>
</div>
<p> Then we&#8217;d never enter that block. Why? </p>
<p> Here are more examples of <i>boolean expressions</i>, where we use the comparion operator <i>greater than &gt;</i>. The first evaluates whether 5 is greater than 10 (False obviously). The second checks if the length of the variable <code>some_list</code> exceeds 100. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ffff0b;">if</span>  5 &gt; 10: <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Evaluate to False</span>
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"5 is greater than 10, is it really?"</span>)

<span style="color: #ffff0b;">if</span> <span style="color: #ff9029;">len</span>(some_list) &gt; 100: <span style="color: #767283;"># </span><span style="color: #767283; font-style: italic;">Test if the list has more than 100 elements</span>
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"You have more than 100 elements in the list"</span>)

</pre>
</div>
<p> The purpose is to only execute part of the code when the <i>boolean expression</i> is True. In the above example it&#8217;s simply just one <code>print</code> statement. This is something we will see more of and learn about as we move along. </p>
<p> This type of logic becomes important as you want develop the program, also when when you want to put constraints in your program. </p>
<p> Imagine a scenario to never allow more than 5 exercises per workout day, or where you can limit the number of sessions total per week. All these things require some kind of <i>conditional logic</i> to exist in your program. Therefore as you gain experience and  develop the program, it&#8217;s only you as the designer of the program that can decide what is valid in your program or not. </p>
<p> Finally, let&#8217;s look at how to combine multiple expressions, to check several conditions at the same time. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ffff0b;">if</span> Expression1 <span style="color: #ffff0b;">or</span> Expression2:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"we use the or-condition"</span>)

<span style="color: #ffff0b;">if</span> answer == <span style="color: #ff7fff;">"Yes"</span> <span style="color: #ffff0b;">or</span> answer == <span style="color: #ff7fff;">"yes"</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"You entered Yes..."</span>)
</pre>
</div>
<p> The second example becomes handy when you want to let a user be more flexible, you will allow &#8220;Yes&#8221; and &#8220;yes&#8221; as an answer to a question, you&#8217;ll try to implement this in your program too with the exercises. </p>
</div>
</div>
<div id="outline-container-org921a121" class="outline-2">
<h2 id="org921a121">Python for-loop &#8211; loop through exercises with</h2>
<div class="outline-text-2" id="text-org921a121">
<p> Now let&#8217;s get back to our program, and look at the first branch i.e. the boolean expression where the user type &#8220;Yes&#8221; &#8211; we&#8217;ll introduce the concept of loops now. Remember, the program should display all exercises, according to the question presented to the user </p>
<div class="org-src-container">
<label class="org-src-name"><em> Name: for loop.</em></label></p>
<pre class="src src-python" id="for loop"><span style="color: #4ac964;">response</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">'Would you like to see all exercises in the training schedule? (Yes/No) '</span>)

<span style="color: #ffff0b;">if</span> response == <span style="color: #ff7fff;">"Yes"</span>:
  <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"Here are all the exercises:"</span>)
  <span style="color: #ffff0b;">for</span> exercise <span style="color: #ffff0b;">in</span> exercises:
    <span style="color: #ff9029;">print</span>(exercise)
</pre>
</div>
<p> Notice the construct: keyword <code>for</code> followed by a variable, followed by keyword <code>in</code> followed by a variable (a list or tuple). </p>
<p> <code>for variable1 in variable2</code> </p>
<p> This tells the program to <b>loop through each element</b> in a data structure (like a list or tuple) and execute the code in the loop for each individual element. For our program, it will print each exercise on a separate line, and the output should look like the following. Run the program and confirm you see the same. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil">Bench press
Deadlift
Squat
Biceps curl
</pre>
</div>
<p> On each iteration <code>print(exercise)</code> works because <code>exercise</code> is <i>bound</i> or assigned the value from the tuple, one value at a time. </p>
<p> In this example: </p>
<ol class="org-ol">
<li><b>Starting the loop</b>: <code>for exercise in exercises</code> means that Python starts going through each element in <code>exercises</code>.</li>
<li><b>Assignment</b> of <code>exercise</code> : For each iteration (loop), <code>exercise</code> becomes the name of one exercise in turn, from &#8216;Bench press&#8217; to &#8216;Biceps curl.&#8217;</li>
<li><b>Executing instructions</b>: The code in the loop, <code>print(exercise)</code>, is executed each time the loop repeats. So each exercise is printed on its own line.</li>
</ol>
<p> Insert another statement inside the for-loop block, right above <code>print(exercises)</code> and see the result. Don&#8217;t forget to add same indentation. </p>
</div>
<div id="outline-container-org2960c76" class="outline-3">
<h3 id="org2960c76">How many iterations does the loop run?</h3>
<div class="outline-text-3" id="text-org2960c76">
<p> It depends on the number of elements in the list – the purpose of a <code>for</code> loop is to go through all the elements in the list. The answer is <code>len(exercises)</code>, try printing it after the loop. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">"The length of exercises is "</span>, <span style="color: #ff9029;">len</span>(exercises))
</pre>
</div>
<p> Alternatively, imagine if you had a really long list, you&#8217;d have to print each exercise on its own line. Something that would become cumbersome quickly. </p>
<div class="org-src-container">
<label class="org-src-name"><em> Name: inefficient code.</em></label></p>
<pre class="src src-python" id="inefficient code"><span style="color: #ffff0b;">if</span> response == <span style="color: #ff7fff;">'Yes'</span>:
    <span style="color: #ff9029;">print</span>(exercises[0])
    <span style="color: #ff9029;">print</span>(exercises[1])
    <span style="color: #ff9029;">print</span>(exercises[2])
    <span style="color: #ff9029;">print</span>(exercises[3])
</pre>
</div>
<p> Now you see the purpose of the the for loop to handle the list (or tuple) efficiently. So, if we had 10 exercises, the for loop wouldn&#8217;t change at all. However, you&#8217;d have to add 6 more rows of <code>print</code>, which one is better? </p>
<p> <i>Remember</i> a <code>for</code>-loop in Python is a powerful tool for repeating instructions multiple times – perfect for lists and other collections. Using <code>for</code>-loops, we can work efficiently with collections of data and make the program more flexible. Feel free to add your own instructions inside the loop to experiment with how you can handle each element in a list. </p>
<div class="org-src-container">
<label class="org-src-name"><em> Name: complete for-loop.</em></label></p>
<pre class="src src-python" id="complete for-loop"><span style="color: #ffff0b;">if</span> response == <span style="color: #ff7fff;">'Yes'</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Here are all the exercises:'</span>)
    <span style="color: #ffff0b;">for</span> exercise <span style="color: #ffff0b;">in</span> exercises:
        <span style="color: #ff9029;">print</span>(exercise)
<span style="color: #ffff0b;">elif</span> response == <span style="color: #ff7fff;">'No'</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Okay, we won&#8217;t show any exercises right now.'</span>)
<span style="color: #ffff0b;">else</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Invalid response, please type "Yes" or "No".'</span>)
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orgd6f0ee7" class="outline-2">
<h2 id="orgd6f0ee7">Use the operator &#8220;in&#8221;</h2>
<div class="outline-text-2" id="text-orgd6f0ee7">
<p> Python has a neat operator we can use called <code>in</code>. Let&#8217;s demonstrate how to use it in our program. Extend the program by adding a new question asking the user which exercise details to display. In programming terms, we want to <i>search</i> the tuple <code>exercises</code> for a <i>value</i>, namely the exercise the user type into the program dialogue. </p>
<p> As a result, we’ll just print a generic message for each exercise. Add the following after the code above: </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #4ac964;">selected_exercise</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">'Which exercise would you like to know more about? '</span>)

<span style="color: #ffff0b;">if</span> selected_exercise <span style="color: #ffff0b;">in</span> exercises:
    <span style="color: #ff9029;">print</span>(f<span style="color: #ff7fff;">'You chose </span>{selected_exercise}<span style="color: #ff7fff;">. This is a fundamental exercise for building strength.'</span>)
<span style="color: #ffff0b;">else</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'That exercise is not in the schedule.'</span>)
</pre>
</div>
<p> Here, we use <code>in</code> to check if the exercise entered by the user exists in <code>exercises</code>. If it does, we display information about the exercise; otherwise, we inform the user that the exercise isn’t in the schedule. </p>
</div>
</div>
<div id="outline-container-org012ddef" class="outline-2">
<h2 id="org012ddef">The complete program code</h2>
<div class="outline-text-2" id="text-org012ddef">
<div class="org-src-container">
<label class="org-src-name"><em> Name: training_app_pt2.py.</em></label></p>
<pre class="src src-python" id="training_app_pt2.py"><span style="color: #4ac964;">week</span> = 1
<span style="color: #4ac964;">schedule</span> = <span style="color: #ff7fff;">'Workout A'</span>
<span style="color: #4ac964;">exercises</span> = (<span style="color: #ff7fff;">'Bench press'</span>, <span style="color: #ff7fff;">'Deadlift'</span>, <span style="color: #ff7fff;">'Squat'</span>, <span style="color: #ff7fff;">'Biceps curl'</span>)

<span style="color: #4ac964;">response</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">'Would you like to see all exercises in the training schedule? (Yes/No) '</span>)

<span style="color: #ffff0b;">if</span> response == <span style="color: #ff7fff;">'Yes'</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Here are all the exercises:'</span>)


<span style="color: #ffff0b;">elif</span> response == <span style="color: #ff7fff;">'No'</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Okay, we won&#8217;t show any exercises right now.'</span>)
<span style="color: #ffff0b;">else</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'Invalid response, please type "Yes" or "No".'</span>)

    <span style="color: #4ac964;">selected_exercise</span> = <span style="color: #ff9029;">input</span>(<span style="color: #ff7fff;">'Which exercise would you like to know more about? '</span>)

<span style="color: #ffff0b;">if</span> selected_exercise <span style="color: #ffff0b;">in</span> exercises:
    <span style="color: #ff9029;">print</span>(f<span style="color: #ff7fff;">'You chose </span>{selected_exercise}<span style="color: #ff7fff;">. This is a fundamental exercise for building strength.'</span>)
<span style="color: #ffff0b;">else</span>:
    <span style="color: #ff9029;">print</span>(<span style="color: #ff7fff;">'That exercise is not in the schedule.'</span>)

</pre>
</div>
</div>
</div>
<div id="outline-container-orgf129ed7" class="outline-2">
<h2 id="orgf129ed7">Exercises</h2>
<div class="outline-text-2" id="text-orgf129ed7">
<ol class="org-ol">
<li>Extend the <code>exercises</code> tuple with more exercises.</li>
<li>Improve the exercise details, by creating a different messages for each exercise. You&#8217;d need to write an if-statements inside an if-statement.</li>
<li>Extend the if-statement to for the word No, with both uppercase and lowercase &#8220;N&#8221;. The user should be able to enter either &#8220;no&#8221; or &#8220;No&#8221;.</li>
<li>Extend the if-statement in previous exercise to allow more alternatives, e.g. &#8220;Nope&#8221;, &#8220;Nah&#8221; or whatever you can think of.</li>
<li>In the next part, we’ll use a <b>dictionary</b> to store descriptions for each exercise in a cleaner way.</li>
<li>Another loop is the while-loop, go to docs.python.org to find out more about it. Use the function <code>len()</code> to determine the condition.</li>
</ol>
</div>
</div>
<div id="outline-container-org5854a2e" class="outline-2">
<h2 id="org5854a2e">Terminology</h2>
<div class="outline-text-2" id="text-org5854a2e">
<p> Review these terms </p>
<ul class="org-ul">
<li>tuple</li>
<li>list</li>
<li>if-statement</li>
<li>for-loop</li>
<li>boolean expression</li>
</ul>
</div>
</div>
<div id="outline-container-orgafe4b3d" class="outline-2">
<h2 id="orgafe4b3d">Summary</h2>
<div class="outline-text-2" id="text-orgafe4b3d">
<p> In this part, you’ve seen how to use the <code>if</code>-statements in order to handle different scenarios in your program. It allow your program to become more interactive, but also handle things in the code to work according to your plan. Being able to create different options and decision paths in a program is an important part of programming. This makes programs more dynamic and user-friendly. </p>
<p> In the next part, we’ll dive deeper into working with <b>loops</b> and explore <b>dictionaries</b>. </p>
<p> If you&#8217;ve missed the previous post, check it out <a href="https://heaplevel.com/?p=450">Python if-statements &#8211; beginning the training app</a> </p>
<p> See you in the next section! </p>
</div>
</div><p>The post <a href="https://heaplevel.com/blog/python-if-statements-and-loops/">Python If Statements and Loops (Lazy Beginner Tutorial)</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How To Install Python On Your Computer</title>
		<link>https://heaplevel.com/blog/how-to-install-python-on-your-computer/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Sat, 14 Dec 2024 08:48:05 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=337</guid>

					<description><![CDATA[<p>Installing or updating Python can sometimes be a little tricky and it&#8217;s confusing to understand which version is actually installed. Don&#8217;t worry in this tutorial we show you how to handle that. One of the downsides of Python is setting up the environment in a correct way and the fact that there are a multitude &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/blog/how-to-install-python-on-your-computer/" class="more-link">Continue reading<span class="screen-reader-text"> "How To Install Python On Your Computer"</span></a></p>
<p>The post <a href="https://heaplevel.com/blog/how-to-install-python-on-your-computer/">How To Install Python On Your Computer</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">Installing or updating Python can sometimes be a little tricky and it&#8217;s confusing to understand which version is actually installed. Don&#8217;t worry in this tutorial we show you how to handle that. One of the downsides of Python is setting up the environment in a correct way and the fact that there are a multitude of installation methods can make the beginner unsure about which Python version is installed. </p>



<p class="wp-block-paragraph">If you install Visual Studio Code it cannot guarantee that your configuration is in the right place when the time comes to code and run your scripts.</p>



<h3 class="wp-block-heading"><mark style="background-color:#005075" class="has-inline-color has-white-color">Common ways to install Python</mark></h3>



<p class="wp-block-paragraph">You can download official Python distributions from&nbsp;<a href="https://python.org/">Python.org</a>, install from a package manager, and even install specialized distributions for scientific computing, Internet of Things, and embedded systems.&nbsp;</p>



<p class="wp-block-paragraph">This tutorial focuses on official distributions, as they’re generally the best option for getting started with learning to program in Python.</p>



<p class="wp-block-paragraph"><strong>In this tutorial you’ll learn how to:</strong></p>



<ul class="wp-block-list">
<li>Check which&nbsp;<strong>version</strong>&nbsp;of Python, if any, is installed on your machine</li>



<li>Install or update Python on&nbsp;<strong>Windows</strong>,&nbsp;<strong>macOS</strong>, and&nbsp;<strong>Linux</strong></li>
</ul>



<p class="wp-block-paragraph">This is different depending on your operating system. There&#8217;s also the option of using Anaconda or even pyenv.</p>



<p class="wp-block-paragraph">Depending on your use case I&#8217;d recommend different options. </p>



<h3 class="wp-block-heading" id="pythonbeginnerinstall">Install Python as a beginner for the first time</h3>



<p class="wp-block-paragraph">This method is common for beginners and applies regardless of operating system you are running. The process the most recognizable for newcomers and is highly recommended.</p>



<ol class="wp-block-list">
<li>Go to <a href="http://python.org/downloads">python.org/downloads</a></li>



<li>Select the correct version for your operating system. The site should handle it automatically for you. It will look something like the following </li>
</ol>



<figure class="wp-block-image size-large"><a href="https://heaplevel.com/wp-content/uploads/2024/02/image.png"><img fetchpriority="high" decoding="async" width="1024" height="405" src="https://heaplevel.com/wp-content/uploads/2024/02/image-1024x405.png" alt="" class="wp-image-340" srcset="https://heaplevel.com/wp-content/uploads/2024/02/image-1024x405.png 1024w, https://heaplevel.com/wp-content/uploads/2024/02/image-300x119.png 300w, https://heaplevel.com/wp-content/uploads/2024/02/image-768x304.png 768w, https://heaplevel.com/wp-content/uploads/2024/02/image.png 1224w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p class="wp-block-paragraph">Proceed to installing and following the default instructions of the installer.</p>



<p class="wp-block-paragraph">If you are on Windows, then go to the Start Menu and search for &#8220;IDLE&#8221;. That should start the default Python interpreter window.</p>



<p class="wp-block-paragraph">If you are on MacOS then use Spotlight (Command + Space) and search for &#8220;IDLE&#8221;. Or use Finder to go to Applications -&gt; IDLE</p>



<p class="wp-block-paragraph">If you are on Linux then you probably need to unzip the artifact/package just downloaded, or in the best case the installer is ready made to just double click. </p>



<h3 class="wp-block-heading">If you are using Linux</h3>



<p class="wp-block-paragraph">If you are following from the <a href="#pythonbeginnerinstall" data-type="internal" data-id="#pythonbeginnerinstall">section </a>above, and you are not able to double click the package, then you must probably unzip the package with a tool like, tar, bunzip, gunzip. </p>



<p class="wp-block-paragraph">If you&#8217;re diving right into the terminal, lets first of all check which Python version your Linux distribution comes with.</p>



<p class="wp-block-paragraph">Sometimes you may have <code>python</code>, <code>python2</code> or <code>python3</code> command available, or sometimes all of them. You can check the system Python version as the following</p>



<p class="wp-block-paragraph"><code>$ python --version</code></p>



<p class="wp-block-paragraph"><code>$ python2 --version</code></p>



<p class="wp-block-paragraph"><code>$ python3 --version</code></p>



<p class="wp-block-paragraph">If any command gives an error, then you don&#8217;t have that version installed.</p>



<p class="wp-block-paragraph">Easier would be, if you type <code>which python</code> then your terminal will show which binary is executed and linked to that <code>python</code> command &#8212; given that it exists on your system of course.</p>



<p class="wp-block-paragraph"><strong>If you are using Ubuntu</strong> then go ahead and do the following.</p>



<pre class="wp-block-code"><code>$ sudo apt update
$ sudo apt install python3</code></pre>



<p class="wp-block-paragraph">If the above raises an error, then you need to find which Python-version exists in your package manager and use that when you install. First search for the correct name like this.</p>



<pre class="wp-block-code"><code>$ apt search python</code></pre>



<h3 class="wp-block-heading">If you are using Windows</h3>



<p class="wp-block-paragraph">Installing on Windows can get a bit complicated, but this guide will hopefully sort things out for you. The most simple method is to go to <a href="http://python.org/downloads">http://python.org/downloads</a> and download the latest Python version for Windows. If you&#8217;re just a beginner then Windows also offers a very simple method through their Microsoft Store. None of these steps below are necessary if you followed the steps in the first section of <a href="#pythonbeginnerinstall" data-type="internal" data-id="#pythonbeginnerinstall">this post</a></p>



<p class="wp-block-paragraph"><strong>Install Python via The Microsoft Store method</strong></p>



<p class="wp-block-paragraph">Open up Microsoft Store and search for Python. Select the latest version and install it.</p>



<figure class="wp-block-image size-large"><a href="https://heaplevel.com/wp-content/uploads/2024/03/image-4.png"><img decoding="async" width="1024" height="322" src="https://heaplevel.com/wp-content/uploads/2024/03/image-4-1024x322.png" alt="" class="wp-image-348" srcset="https://heaplevel.com/wp-content/uploads/2024/03/image-4-1024x322.png 1024w, https://heaplevel.com/wp-content/uploads/2024/03/image-4-300x94.png 300w, https://heaplevel.com/wp-content/uploads/2024/03/image-4-768x242.png 768w, https://heaplevel.com/wp-content/uploads/2024/03/image-4-1536x484.png 1536w, https://heaplevel.com/wp-content/uploads/2024/03/image-4-1568x494.png 1568w, https://heaplevel.com/wp-content/uploads/2024/03/image-4.png 1855w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p class="wp-block-paragraph"><strong>Do you already have a Python version installed?</strong></p>



<ol class="wp-block-list">
<li>Open Powershell by going to Start menu</li>



<li>Type in PowerShell, see screenshot</li>



<li>Type the following in the new PowerShell window: <code>python --version</code></li>
</ol>



<p class="wp-block-paragraph">If you don&#8217;t get an error from the last step, then you should see the Python version installed on your Windows system. In this case you don&#8217;t need to do anything more.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"><strong>Step 1</strong> &#8211; Locate and open PowerShell</p>



<figure class="wp-block-image size-full"><a href="https://heaplevel.com/wp-content/uploads/2024/03/image-1.png"><img decoding="async" width="615" height="669" src="https://heaplevel.com/wp-content/uploads/2024/03/image-1.png" alt="" class="wp-image-345" srcset="https://heaplevel.com/wp-content/uploads/2024/03/image-1.png 615w, https://heaplevel.com/wp-content/uploads/2024/03/image-1-276x300.png 276w" sizes="(max-width: 615px) 100vw, 615px" /></a></figure>



<p class="wp-block-paragraph"><strong>Step 2</strong> &#8211; Check Python version if it&#8217;s installed</p>



<figure class="wp-block-image size-full"><a href="https://heaplevel.com/wp-content/uploads/2024/03/image-2.png"><img loading="lazy" decoding="async" width="854" height="227" src="https://heaplevel.com/wp-content/uploads/2024/03/image-2.png" alt="" class="wp-image-346" srcset="https://heaplevel.com/wp-content/uploads/2024/03/image-2.png 854w, https://heaplevel.com/wp-content/uploads/2024/03/image-2-300x80.png 300w, https://heaplevel.com/wp-content/uploads/2024/03/image-2-768x204.png 768w" sizes="auto, (max-width: 854px) 100vw, 854px" /></a></figure>



<p class="wp-block-paragraph"><strong>Step 3</strong> &#8211; Decide installation method</p>



<p class="wp-block-paragraph">If you don&#8217;t have Python installed already then go ahead and either download Python from the official website or the Microsoft Store</p>



<p class="wp-block-paragraph"><strong>Step 4 &#8211; </strong>Open up IDLE</p>



<p class="wp-block-paragraph">This step is the same as earlier, you can start the IDLE program by going to the Start menu and typing &#8220;IDLE&#8221; like the screenshot below. You see that I have several versions of Python installed at the same time, this is not a problem at all. </p>



<figure class="wp-block-image size-large"><a href="https://heaplevel.com/wp-content/uploads/2024/12/image.png"><img loading="lazy" decoding="async" width="1024" height="888" src="https://heaplevel.com/wp-content/uploads/2024/12/image-1024x888.png" alt="" class="wp-image-401" srcset="https://heaplevel.com/wp-content/uploads/2024/12/image-1024x888.png 1024w, https://heaplevel.com/wp-content/uploads/2024/12/image-300x260.png 300w, https://heaplevel.com/wp-content/uploads/2024/12/image-768x666.png 768w, https://heaplevel.com/wp-content/uploads/2024/12/image.png 1170w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></figure>



<h3 class="wp-block-heading">EXTRA &#8211; Try online editors for Python</h3>



<p class="wp-block-paragraph">You can also try to experiment with Python without installing anything on your computer. Click the following site for example</p>



<p class="wp-block-paragraph"><a href="https://www.python.org/shell/">https://www.python.org/shell/</a><br><a href="http://repl.it">https://repl.it</a> &#8211; advanced</p>



<p class="wp-block-paragraph"></p><p>The post <a href="https://heaplevel.com/blog/how-to-install-python-on-your-computer/">How To Install Python On Your Computer</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Python and the Building Blocks of Programming</title>
		<link>https://heaplevel.com/blog/python-and-the-building-blocks-of-programming/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Sat, 29 Jun 2024 22:00:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=393</guid>

					<description><![CDATA[<p>Table of Contents Python and the Building Blocks of Programming Goals of This Post Series Building Blocks of a Program Examples of how building blocks are used Building block 1 &#8211; Variables Exercise Python and the Building Blocks of Programming Goals of This Post Series You will learn the anatomy of a program and what &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/blog/python-and-the-building-blocks-of-programming/" class="more-link">Continue reading<span class="screen-reader-text"> "Python and the Building Blocks of Programming"</span></a></p>
<p>The post <a href="https://heaplevel.com/blog/python-and-the-building-blocks-of-programming/">Python and the Building Blocks of Programming</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#orgc3918b5">Python and the Building Blocks of Programming</a>
<ul>
<li><a href="#org5a963ad">Goals of This Post Series</a></li>
<li><a href="#orgbe9549a">Building Blocks of a Program</a></li>
<li><a href="#org73e47e4">Examples of how building blocks are used</a></li>
<li><a href="#orgc3ba110">Building block 1 &#8211; Variables</a></li>
<li><a href="#org3fb732d">Exercise</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-orgc3918b5" class="outline-2">
<h2 id="orgc3918b5">Python and the Building Blocks of Programming</h2>
<div class="outline-text-2" id="text-orgc3918b5">
</div>
<div id="outline-container-org5a963ad" class="outline-3">
<h3 id="org5a963ad">Goals of This Post Series</h3>
<div class="outline-text-3" id="text-org5a963ad">
<ul class="org-ul">
<li>You will learn the anatomy of a program and what a typical Python program consists of.</li>
<li>Introduce variables, data structures and functions as basic building blocks of a program</li>
<li>Introduce classes and objects as <i>advanced</i> building blocks of a program.</li>
</ul>
<p> Each building blocks can be used in different ways, and not all of them are required in a single program. Using these blocks, we can gradually construct our program in different ways until we achieve the desired functionality. </p>
<p> By the end of this post, you will have a first introduction of what constitutes a basic Python program by understanding what variables are. </p>
<p> In the next post you will be able to create interactive dialogues with users and store information in variables and data structures. </p>
<p> <b>Data handling</b> is a fundamental of any program so it&#8217;s important to understand this early on. </p>
</div>
</div>
<div id="outline-container-orgbe9549a" class="outline-3">
<h3 id="orgbe9549a">Building Blocks of a Program</h3>
<div class="outline-text-3" id="text-orgbe9549a">
<p> Every program is made up of one or more building blocks. We will explore all of them in a series of posts in this blog. </p>
<ul class="org-ul">
<li>Variables</li>
<li>Data Structures</li>
<li>Functions</li>
<li>Classes</li>
</ul>
<div id="org3f7ecb5" class="figure">
<p><img decoding="async" src="https://heaplevel.com/wp-content/uploads/2025/01/programming_building_blocks_blog.jpg" alt="programming_building_blocks_blog.jpg" /> </p>
</p></div>
</div>
</div>
<div id="outline-container-org73e47e4" class="outline-3">
<h3 id="org73e47e4">Examples of how building blocks are used</h3>
<div class="outline-text-3" id="text-org73e47e4">
<p> Each building block serves a specific purpose, categorized into storing information (data) or processing it. </p>
<p> Examples of processing information could be: </p>
<ul class="org-ul">
<li>Calculating VAT given a price.</li>
<li>Determining loan costs based on loan amount and interest rate.</li>
<li>Extracting parts of speech (e.g., verbs, nouns) from a long text or simply calculating the text&#8217;s length.</li>
<li>Calculating age based on a birthdate.</li>
</ul>
<p> Examples of holding (storing) information could be: </p>
<ul class="org-ul">
<li>Storing personal details throughout a program</li>
<li>Storing account balance</li>
<li>Storing textual information about a book or news site</li>
</ul>
<p> Here&#8217;s an example of some building blocks in a program, feel free to try it out in your Python environment. </p>
<p> Have you not installed Python yet? Check out the simple guide we have </p>
<p> <a href="https://heaplevel.com/?p=337">How To Install Python On Your Computer</a> </p>
</div>
</div>
<div id="outline-container-orgc3ba110" class="outline-3">
<h3 id="orgc3ba110">Building block 1 &#8211; Variables</h3>
<div class="outline-text-3" id="text-orgc3ba110">
<p> For the examples in this post, it&#8217;s sufficient to write them in IDLE. However, if you are already familiar or prefer VSCode, PyCharm or another editor, feel free to do so. </p>
<p> Each file you create are called a <i>module</i>. You may encounter both when you read online resources. </p>
<p> To create a new file in IDLE, go to <b>File -&gt; New File</b>. Name the new file <code>building_blocks_ex1.py</code>. </p>
<div id="orgff54be8" class="figure">
<p><img decoding="async" src="https://heaplevel.com/wp-content/uploads/2025/01/idle_newfile.jpg" alt="idle_newfile.JPG" /> </p>
</p></div>
<p> You will see an empty window where you can write your code. Paste the following code and then go to <b>Run -&gt; Run Module</b>. </p>
<div class="org-src-container">
<label class="org-src-name"><em></em></label></p>
<pre class="src src-python" id="nil"><span style="color: #4eee94;">name</span> = <span style="color: #deb887;">'Karl'</span>
<span style="color: #4eee94;">direction</span> = <span style="color: #deb887;">'North'</span>
<span style="color: #4eee94;">cost</span> = 200
<span style="color: #f08080;">print</span>(name)
<span style="color: #f08080;">print</span>(direction)
<span style="color: #f08080;">print</span>(cost)
</pre>
</div>
<p> The example above demonstrates a short program showcasing variables, assignment, and output. The left hand side is the variable name and the right hand side is the value assigned to that variable. </p>
<p> A variable is a container to store data in your program. </p>
<p> Python has many built-in functions that we will use, one of them is the useful <code>print()</code>. That will output to your window the result of each variable we created: name, direction and cost. </p>
</div>
</div>
<div id="outline-container-org3fb732d" class="outline-3">
<h3 id="org3fb732d">Exercise</h3>
<div class="outline-text-3" id="text-org3fb732d">
<p> Practice writing your own variables. Notice the following </p>
<ul class="org-ul">
<li>What happens if you change single quote to double quotes?</li>
<li>Can you change cost to something other than a number? Like a name?</li>
<li>Create a new variable and name it, e.g. salary, age, points &#8211; use your imagination!</li>
<li>Print the newly created variable(s).</li>
<li>What happen if you combine the <code>print</code> like so print(name, direction, cost)?</li>
</ul>
<p> This was a short introduction to <code>variables</code> and already in the next post we will build on this to interact with a user. </p>
</div>
</div>
</div><p>The post <a href="https://heaplevel.com/blog/python-and-the-building-blocks-of-programming/">Python and the Building Blocks of Programming</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Host your Discord Bot &#8211; 3 popular options</title>
		<link>https://heaplevel.com/blog/3-ways-to-setup-a-discord-bot-on-your-server/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Tue, 13 Apr 2021 12:06:21 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[discord]]></category>
		<category><![CDATA[discord bot]]></category>
		<category><![CDATA[guide]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=291</guid>

					<description><![CDATA[<p>Having your own Discord Bot can be a nice way of adding a custom experience to your users on the server. In order to host your Discord bot, a maintainer has a couple of options to look at before deciding which is the right one. Along the way, there are also a couple of things &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/blog/3-ways-to-setup-a-discord-bot-on-your-server/" class="more-link">Continue reading<span class="screen-reader-text"> "Host your Discord Bot &#8211; 3 popular options"</span></a></p>
<p>The post <a href="https://heaplevel.com/blog/3-ways-to-setup-a-discord-bot-on-your-server/">Host your Discord Bot – 3 popular options</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">Having your own Discord Bot can be a nice way of adding a custom experience to your users on the server. In order to host your Discord bot, a maintainer has a couple of options to look at before deciding which is the right one. Along the way, there are also a couple of things to take into consideration when you want to host a Discord Bot on your server. You can first of course look if your needs are met by a bot from <a href="https://top.gg/" target="_blank" rel="noreferrer noopener">https://top.gg/</a>. Otherwise you can write your own and for that there are more things to consider.</p>



<h3 class="wp-block-heading">What to Consider </h3>



<ul class="wp-block-list">
<li>Which language is the bot written in?</li>



<li>How do you want to host it? What matters to you?
<ul class="wp-block-list">
<li>personal support</li>



<li>uptime</li>



<li>monitoring</li>
</ul>
</li>
</ul>



<p class="wp-block-paragraph">There are popular languages to write your bot in, some of the popular are</p>



<ul class="wp-block-list">
<li> Java</li>



<li>Python</li>



<li>NodeJS.</li>
</ul>



<h2 class="wp-block-heading">Host options for a Discord Bot</h2>



<p class="wp-block-paragraph">The common ways to setup a Discord Bot can be</p>



<ul class="wp-block-list">
<li>VPS on your own</li>



<li>External hosting provider, in fact that&#8217;s exactly what we can help you with. Check out our process and pipeline for deploying the Heaplevel Discord bot <a data-type="post" data-id="302" href="https://heaplevel.com/blog/how-we-deploy-our-discord-bot/" target="_blank" rel="noreferrer noopener">here</a>.</li>



<li>Locally on your desktop</li>
</ul>



<p class="wp-block-paragraph">Let&#8217;s start with the first one VPS. How is the process to get the bot up and running usually? </p>



<h2 class="wp-block-heading">Discord Bot Hosted on a VPS</h2>



<ol class="wp-block-list">
<li>Setup VPS by registering a new account at a hosting provider</li>



<li>Login to the VPS and access the terminal</li>



<li>Install the programming environment necessary. This depends on which language you have written your bot in. It could be Python, NodeJS, Java or anything else.</li>



<li>The code. You need a way to transfer the code to the actual VPS machine. Either it&#8217;s on a code repository like Github or Bitbucket. Or you can transfer it via some UI file manager. Check with your provider. </li>



<li>When you have the code locally, it&#8217;s smart to test run it. this step verifies that you have all the necessary tools for your bot to run. How you do that depends on your code base again. This is probably something you&#8217;ve already tried when developing the code locally on your own desktop machine. </li>



<li>If you have verified the code works then it&#8217;s time to setup the code to run your server. You can either run your main file as a standalone process, setup a cronjob or write a containerized version of it (link to Docker article &#8211; How to run a Docker discord bot).</li>



<li>This step is ususally skipped but if you have the chance to monitor the resource usage on the server it&#8217;s a major plus.</li>



<li>Handle updates to the code</li>



<li>Handle bot crashes &#8211; due to usage utilization or anything else</li>
</ol>



<p class="wp-block-paragraph">With these things we can also support you if you run into problems. </p>



<h2 class="wp-block-heading">Discord Bot hosted on a external hosting provider</h2>



<p class="wp-block-paragraph">While the registration part is usually the same as for VPS, the real advantage is that an external hosting provider will provide you with an interface for uploading your code and run it. Usually there is an amount of support included in your account. A good hosting provider will allow you to just point to a repository on GitHub or BitBucket for example instead of you manually uploading the files to the server. </p>



<p class="wp-block-paragraph">The steps are usually</p>



<ol class="wp-block-list">
<li>Register your account with the Discord bot hosting provider</li>



<li>Upload your files </li>



<li>Start the bot through the provider&#8217;s integrated interface</li>
</ol>



<h2 class="wp-block-heading">Discord Bot locally on your desktop</h2>



<p class="wp-block-paragraph">Let&#8217;s say you have a little desktop machine laying there without a purpose, you can use it as your local little server. This scenario can look different depending on your setup. But it&#8217;s closest to preparing your VPS for Discord Bot. You will need the following</p>



<ol class="wp-block-list">
<li>Development environment for the language the bot is written in</li>



<li>Some scheduling and monitoring mechanism if the Discord bot will crash. </li>



<li>If you are sure that everything is complete, then you can run the bot through the development environment on the desktop computer.</li>
</ol>



<h2 class="wp-block-heading">Summary</h2>



<p class="wp-block-paragraph">We have looked at different options for setting up your Discord Bot. While they look similar, the decision boils down to what&#8217;s important for you. The requirements you have will differ to somebody else. Some are happy with no support from their provider while others are happy to outsource that task to someone else. You still need a fair amount of knowledge to setup the Discord bot on the underlying system, usually in Linux you require a little more experience. </p>



<p class="wp-block-paragraph">If you find yourself in need of discussing this with us then it&#8217;s something we can provide support for. Even if you have support from your provider, drop us an email. </p>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="wp-block-button is-style-fill"><a class="wp-block-button__link wp-element-button" href="https://heaplevel.com/hosting-your-discord-bot/" target="_blank" rel="noreferrer noopener">I Need Help With My Discord Bot</a></div>
</div><p>The post <a href="https://heaplevel.com/blog/3-ways-to-setup-a-discord-bot-on-your-server/">Host your Discord Bot – 3 popular options</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to open a file in Python in different modes</title>
		<link>https://heaplevel.com/blog/how-to-open-a-file-in-python-in-different-modes/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Fri, 16 Aug 2019 06:51:48 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=94</guid>

					<description><![CDATA[<p>Opening a file in Python is really simple. How do you create a file though that doesn&#8217;t exist? If you use the open function in Python like so You&#8217;ll run into the error Mode for open a file We need to understand that opening a file can be followed by a mode parameter, the signature &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/blog/how-to-open-a-file-in-python-in-different-modes/" class="more-link">Continue reading<span class="screen-reader-text"> "How to open a file in Python in different modes"</span></a></p>
<p>The post <a href="https://heaplevel.com/blog/how-to-open-a-file-in-python-in-different-modes/">How to open a file in Python in different modes</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">Opening a file in Python is really simple. How do you create a file though that doesn&#8217;t exist?</p>



<p class="wp-block-paragraph">If you use the <em>open</em> function in Python like so</p>



<pre class="wp-block-code"><code>open('file.txt')</code></pre>



<p class="wp-block-paragraph">You&#8217;ll run into the error</p>



<pre class="wp-block-code"><code>FileNotFoundError: [Errno 2] No such file or directory: 'file.txt'</code></pre>



<h2 class="wp-block-heading">Mode for open a file</h2>



<p class="wp-block-paragraph">We need to understand that opening a file can be followed by a mode parameter, the signature for the function is <em>open(file, mode)</em>. </p>



<p class="wp-block-paragraph">If you only submit the filename the default mode is set to &#8216;read&#8217; mode. Which only makes sense if the file exists. Here are the other modes </p>



<ul class="wp-block-list"><li>r &#8211; open for reading (default)</li><li>t &#8211; text mode (default)</li><li>w &#8211; write mode</li><li>a &#8211; append mode</li><li>x &#8211; open file, failing if the file already exists</li><li>b &#8211; <a href="https://en.wikipedia.org/wiki/Binary_file">binary mode</a></li></ul>



<h2 class="wp-block-heading">Open and create the file</h2>



<p class="wp-block-paragraph">Referring to the above table, we can use different modes for creating a file for the first time. Depending on our purpose if we want to delete an existing file with the same name or not.</p>



<p class="wp-block-paragraph">Let&#8217;s try this</p>



<pre class="wp-block-code"><code>file = open('file.txt', 'w')
file.write('First line')
file.close()</code></pre>



<p class="wp-block-paragraph">Do you want to know more about a Python topic? <a href="https://heaplevel.com/contact-us/">Contact us</a> or leave a comment below :).</p><p>The post <a href="https://heaplevel.com/blog/how-to-open-a-file-in-python-in-different-modes/">How to open a file in Python in different modes</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Getting started with Javascript</title>
		<link>https://heaplevel.com/blog/getting-started-with-javascript/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Thu, 25 Jul 2019 16:59:46 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=75</guid>

					<description><![CDATA[<p>If you want to start programming in Javascript you might ask where do you actually start? It might be that you&#8217;ve been interested in learning more about web programming in general, for which it would be useful to also learn about HTML and CSS as well. While HTML and CSS deal with the structure of &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/blog/getting-started-with-javascript/" class="more-link">Continue reading<span class="screen-reader-text"> "Getting started with Javascript"</span></a></p>
<p>The post <a href="https://heaplevel.com/blog/getting-started-with-javascript/">Getting started with Javascript</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">If you want to start programming in Javascript you might ask where do you actually start?</p>



<p class="wp-block-paragraph">It might be that you&#8217;ve been interested in learning more about web programming in general, for which it would be useful to also learn about <a href="https://simplecodeacademy.heaplevel.com">HTML and CSS</a> as well. While HTML and CSS deal with the structure of a website, Javascript adds the dynamic flavour to your website. </p>



<p class="wp-block-paragraph">There is also a possibility that you want to learn Javascript to write backend applications, using NodeJS. The applications for Javascript are several, both websites and web applications can use Javascript. </p>



<p class="wp-block-paragraph">If this is the first time to Javascript you can start by learning about the language itself and start play around in a sandbox environment. That is the best option to learn Javascript. </p>



<h2 class="wp-block-heading">Learn Javascript by examples</h2>



<p class="wp-block-paragraph">We will experiment with Javascript by looking at some examples. This guide is for you that have a little programming background.</p>



<ol class="wp-block-list"><li>Navigate to <a href="https://jsfiddle.net">JSFiddle</a></li><li>Copy the following code in the HTML box</li><li>Hit the Run button. You should see a popup displaying the text &#8220;Hello, world!&#8221;</li></ol>



<pre class="wp-block-code"><code>&lt;!DOCTYPE HTML>
&lt;html>
&lt;head>
&lt;script>
    alert( 'Hello, world!' );
  &lt;/script>
&lt;/head>
&lt;body>
  The body
&lt;/body>

&lt;/html></code></pre>



<p class="wp-block-paragraph">So what did we actually do here? Simply explained we used the Javascript function called <em>alert</em> to write a message in a popup box. </p>



<p class="wp-block-paragraph">Go ahead and create a second alert with a new message. After you hit Run you should have two popup boxes with two different messages.</p>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph"></p><p>The post <a href="https://heaplevel.com/blog/getting-started-with-javascript/">Getting started with Javascript</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to setup Matomo with MariaDB on Docker</title>
		<link>https://heaplevel.com/blog/how-to-setup-matomo-with-mariadb-on-docker/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Tue, 23 Jul 2019 04:02:22 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[mariadb]]></category>
		<category><![CDATA[matomo]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=70</guid>

					<description><![CDATA[<p>This will spin up a Matomo instance on MariaDB running on the default port 3306. You can then access the Matomo instance to continue the installation by navigation to your hostname:3306. E.g. if you&#8217;re running this on your VPS it will be your http://&#60;VPS IP>:3306 http://localhost:3306 if you&#8217;re on your local dev machine. The above &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/blog/how-to-setup-matomo-with-mariadb-on-docker/" class="more-link">Continue reading<span class="screen-reader-text"> "How to setup Matomo with MariaDB on Docker"</span></a></p>
<p>The post <a href="https://heaplevel.com/blog/how-to-setup-matomo-with-mariadb-on-docker/">How to setup Matomo with MariaDB on Docker</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre class="wp-block-code"><code>$ docker run --name matomo-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:latest</code></pre>



<pre class="wp-block-code"><code>$ docker run -d --link matomo-mariadb:db -p 8089:80 -p 3306:3306 matomo</code></pre>



<p class="wp-block-paragraph">This will spin up a Matomo instance on MariaDB running on the default port 3306. You can then access the Matomo instance to continue the installation by navigation to your hostname:3306. E.g. if you&#8217;re running this on your VPS it will be your http://&lt;VPS IP>:3306</p>



<p class="wp-block-paragraph">http://localhost:3306 if you&#8217;re on your local dev machine.</p>



<p class="wp-block-paragraph">The above will not persist your data, in order to do that you need to use volumes on Docker. So if you plan on restarting your Docker container (likely) then you should use volumes. Otherwise when you restart the Docker container you&#8217;ll have to reinstall the Matomo instance.</p>



<pre class="wp-block-code"><code>docker volume create matomo-vol
docker run -d --link matomo-mariadb:db -p 8089:80 -p 3306:3306 -v matomo-vol:/var/www/html matomo
</code></pre>



<p class="wp-block-paragraph"></p><p>The post <a href="https://heaplevel.com/blog/how-to-setup-matomo-with-mariadb-on-docker/">How to setup Matomo with MariaDB on Docker</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Javascript true and false values</title>
		<link>https://heaplevel.com/blog/javascript-true-and-false-values/</link>
		
		<dc:creator><![CDATA[Heaplevel]]></dc:creator>
		<pubDate>Thu, 23 May 2019 09:34:40 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[javascript]]></category>
		<guid isPermaLink="false">https://heaplevel.com/?p=41</guid>

					<description><![CDATA[<p>In Javascript comparing values are not always as straightforward as one would expect. Overcoming that fear of which variables are truthy are sometimes is just as easy as learning which values are falsy. If you remember them (6 values) then you can easily know which values are true. NaN false undefined &#8221;, &#8220;&#8221;, &#8220; &#8211; &#8230; </p>
<p class="link-more"><a href="https://heaplevel.com/blog/javascript-true-and-false-values/" class="more-link">Continue reading<span class="screen-reader-text"> "Javascript true and false values"</span></a></p>
<p>The post <a href="https://heaplevel.com/blog/javascript-true-and-false-values/">Javascript true and false values</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">In Javascript comparing values are not always as straightforward as one would expect. Overcoming that fear of which variables are truthy are sometimes is just as easy as learning which values are falsy. If you remember them (6 values) then you can easily know which values are true.</p>



<ul class="wp-block-list"><li>NaN</li><li>false</li><li>undefined</li><li>&#8221;, &#8220;&#8221;, &#8220; &#8211; the empty string either single quotes, double quotes or template literalts</li><li>0</li><li>null</li></ul>



<p class="wp-block-paragraph">How do you remember these 6 falsy values in Javascript you say? People remember things differently and since all are unique there are many ways to remember. </p>



<p class="wp-block-paragraph">Remember the simple things first, the one number i.e 0 (zero) is always false. That&#8217;s easy to remember right? Also false makes perfect sense to be&#8230;you guessed it:  false. </p>



<p class="wp-block-paragraph">So four values to go, look at this: null, NaN, undefined</p>



<p class="wp-block-paragraph">Finally strings contain text, strings talk, but a string that doesn&#8217;t contain anything can&#8217;t talk, so it should be false.</p>



<p class="wp-block-paragraph">The perfect order</p>



<ul class="wp-block-list"><li>0</li><li>false</li><li>null &#8211; NaN &#8211; undefined &#8212; becomes nullnandefined &#8211; null (and) undefined. Those are three values coerced into one to remember easily!</li><li>empty strings &#8211; can&#8217;t talk, should be false then. &#8221;, &#8220;&#8221;, &#8220;</li></ul>



<p class="wp-block-paragraph"></p><p>The post <a href="https://heaplevel.com/blog/javascript-true-and-false-values/">Javascript true and false values</a> first appeared on <a href="https://heaplevel.com">Heaplevel AB</a>.</p>]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
