You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>In this exercise, we’ll practice string manipulation and slicing. You’ll work with a secret message encoded using various string operations and learn how to apply some new methods like <code>title()</code>, <code>replace()</code> and <code>count()</code>. By following a series of steps, you’ll gradually decode the message. Let’s begin with the encoded message and work through each decoding step:</p>
<divclass="sourceCode cell-code" id="cb1"><preclass="sourceCode python code-with-copy"><codeclass="sourceCode python"><spanid="cb1-1"><ahref="#cb1-1" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Decode a secret message by following a series of instructions.</span></span>
309
309
<spanid="cb1-2"><ahref="#cb1-2" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Each instruction requires you to use different operations and methods.</span></span>
310
310
<spanid="cb1-3"><ahref="#cb1-3" aria-hidden="true" tabindex="-1"></a><spanclass="co"># The encoded message is:</span></span>
@@ -347,7 +347,7 @@ <h1>Decoding secret messages with methods</h1>
<p>In this exercise, we’ll practice using conditional statements to classify temperatures into different categories. We’ll create a program that takes a temperature input from the user and provides a classification based on the temperature range. This exercise will help you understand how to use if-elif-else statements, handle user input, and implement a simple loop for program repetition.</p>
<divclass="sourceCode cell-code" id="cb2"><preclass="sourceCode python code-with-copy"><codeclass="sourceCode python"><spanid="cb2-1"><ahref="#cb2-1" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Use if-elif-else statements to classify the temperature</span></span>
<p>In this exercise, we’ll create an interactive number guessing game for two players. This game will help you practice using loops, conditional statements, and user input handling. You’ll also learn how to implement a simple game logic and manage player turns. This exercise will reinforce your understanding of control structures and basic development concepts in Python.</p>
<divclass="sourceCode cell-code" id="cb3"><preclass="sourceCode python code-with-copy"><codeclass="sourceCode python"><spanid="cb3-1"><ahref="#cb3-1" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Create a number guessing game with 2 players. The first player is the game master and the second player is the guesser. </span></span>
374
374
<spanid="cb3-2"><ahref="#cb3-2" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Start by asking for their names. Then, ask the game master to input the secret number between 1 and 20. </span></span>
375
375
<spanid="cb3-3"><ahref="#cb3-3" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Make sure, that the number is not shown by adding at least 25 new lines after the input prompt. Then, ask the player to guess the number. </span></span>
Copy file name to clipboardExpand all lines: docs/part-03/lecture-functions-presentation.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -785,7 +785,7 @@ <h2>Returning None</h2>
785
785
</div>
786
786
</div>
787
787
<divclass="fragment">
788
-
<p><spanclass="task">> Grouptask:</span> Come up with a function that checks whether a number is positive or negative. It returns <code>"positive"</code> for positive numbers and <code>"negative"</code> for negative numbers.</p>
788
+
<p><spanclass="task">> Grouptask:</span> Come up with a function that checks whether a number is positive or negative. It returns <code>"positive"</code> for positive numbers and <code>"negative"</code> for negative numbers. If the number is zero, it returns <code>None</code>.</p>
<p><spanclass="task">> Grouptask:</span> Come up with a function that checks whether a number is positive or negative. It returns <code>"positive"</code> for positive numbers and <code>"negative"</code> for negative numbers.</p>
686
+
<p><spanclass="task">> Grouptask:</span> Come up with a function that checks whether a number is positive or negative. It returns <code>"positive"</code> for positive numbers and <code>"negative"</code> for negative numbers. If the number is zero, it returns <code>None</code>.</p>
<p>In this exercise, you will practice writing small functions for various tasks. You will also practice using the <code>return</code> statement to return a value from a function and the <code>global</code> keyword to modify a global variable.</p>
<divclass="sourceCode cell-code" id="cb1"><preclass="sourceCode python code-with-copy"><codeclass="sourceCode python"><spanid="cb1-1"><ahref="#cb1-1" aria-hidden="true" tabindex="-1"></a><spanclass="co"># a) </span><spanclass="al">TODO</span><spanclass="co">: Write a function that takes two numbers as input and returns their squared sum.</span></span>
309
309
<spanid="cb1-2"><ahref="#cb1-2" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Your code here</span></span>
<p>In this exercise, you will practice creating different classes for different tasks. You will create a class for a bank account, a class for a car, and a class for a computer.</p>
<divclass="sourceCode cell-code" id="cb2"><preclass="sourceCode python code-with-copy"><codeclass="sourceCode python"><spanid="cb2-1"><ahref="#cb2-1" aria-hidden="true" tabindex="-1"></a><spanclass="co"># a) # </span><spanclass="al">TODO</span><spanclass="co">: Create a class called 'Book' with the following specifications:</span></span>
342
342
<spanid="cb2-2"><ahref="#cb2-2" aria-hidden="true" tabindex="-1"></a><spanclass="co"># - It should have attributes for 'title', 'author', and 'pages'</span></span>
343
343
<spanid="cb2-3"><ahref="#cb2-3" aria-hidden="true" tabindex="-1"></a><spanclass="co"># - Include a method called 'display_info' that prints all the book's information</span></span>
@@ -363,11 +363,14 @@ <h1>Different classes for different tasks</h1>
<p>Remember the number guessing game from the previous tutorial? Well, it’s time to rebuild it. This time, we will use functions to organize the code and make it more reusable. You will learn how to use functions to modularize your code and make it more readable.</p>
<divclass="sourceCode cell-code" id="cb3"><preclass="sourceCode python code-with-copy"><codeclass="sourceCode python"><spanid="cb3-1"><ahref="#cb3-1" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Start by looking at your code from the previous tutorial and think about the different steps that you implemented. </span></span>
368
-
<spanid="cb3-2"><ahref="#cb3-2" aria-hidden="true" tabindex="-1"></a><spanclass="co"># a) Try to modularize each step of the game into a separate function. Name the functions appropriately, to make clear what they do.</span></span>
369
-
<spanid="cb3-3"><ahref="#cb3-3" aria-hidden="true" tabindex="-1"></a><spanclass="co"># b) Enhance the game by adding difficulty levels as described in the bonus task from the previous tutorial. The difference here is that the difficulty level should be given as a parameter to a function. If no difficulty level is given, i.e. the game master just enters an empty input, the function should use a default value of "Medium".</span></span>
370
-
<spanid="cb3-4"><ahref="#cb3-4" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Your code here</span></span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
<divclass="sourceCode cell-code" id="cb3"><preclass="sourceCode python code-with-copy"><codeclass="sourceCode python"><spanid="cb3-1"><ahref="#cb3-1" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Start by looking at your code from the previous tutorial and think about the different steps that you implemented. </span></span>
368
+
<spanid="cb3-2"><ahref="#cb3-2" aria-hidden="true" tabindex="-1"></a><spanclass="co"># a) </span><spanclass="al">TODO</span><spanclass="co">: Try to modularize each step of the game into a separate function. </span></span>
369
+
<spanid="cb3-3"><ahref="#cb3-3" aria-hidden="true" tabindex="-1"></a><spanclass="co"># - Name the functions appropriately, to make clear what they do.</span></span>
370
+
<spanid="cb3-4"><ahref="#cb3-4" aria-hidden="true" tabindex="-1"></a><spanclass="co"># b) </span><spanclass="al">TODO</span><spanclass="co">: Enhance the game by adding difficulty levels as described in the bonus task from the previous tutorial. </span></span>
371
+
<spanid="cb3-5"><ahref="#cb3-5" aria-hidden="true" tabindex="-1"></a><spanclass="co"># - The difference here is that the difficulty level should be given as a parameter to a function. </span></span>
372
+
<spanid="cb3-6"><ahref="#cb3-6" aria-hidden="true" tabindex="-1"></a><spanclass="co"># - If no difficulty level is given, i.e. the game master just enters an empty input, the function should use a default value of "Medium".</span></span>
373
+
<spanid="cb3-7"><ahref="#cb3-7" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Your code here</span></span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
0 commit comments