Skip to content

Commit afc02a9

Browse files
improved tutorial 3
1 parent 2d75fc3 commit afc02a9

29 files changed

+603
-291
lines changed
1 Byte
Binary file not shown.
0 Bytes
Binary file not shown.

docs/part-02/lecture-control-presentation.html

Lines changed: 161 additions & 134 deletions
Large diffs are not rendered by default.

docs/part-02/lecture-control.html

Lines changed: 139 additions & 114 deletions
Large diffs are not rendered by default.

docs/part-02/lecture-control.pdf

1.03 KB
Binary file not shown.

docs/part-02/tutorial-control.html

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ <h1>Introduction</h1>
304304
<section id="decoding-secret-messages-with-methods" class="level1">
305305
<h1>Decoding secret messages with methods</h1>
306306
<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>
307-
<div id="1f8f3042" class="cell" data-execution_count="1">
307+
<div id="7a732846" class="cell" data-execution_count="1">
308308
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Decode a secret message by following a series of instructions.</span></span>
309309
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Each instruction requires you to use different operations and methods.</span></span>
310310
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="co"># The encoded message is:</span></span>
@@ -327,7 +327,7 @@ <h1>Decoding secret messages with methods</h1>
327327
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a><span class="co"># e) </span><span class="al">TODO</span><span class="co">: Add an exclamation mark at the end of the sentence</span></span>
328328
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
329329
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a></span>
330-
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a><span class="co"># f) </span><span class="al">TODO</span><span class="co">: Count how many times the letter 's' appears in the decoded message</span></span>
330+
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a><span class="co"># f) </span><span class="al">TODO</span><span class="co">: Count how many times the letter 's' appears in the decoded message (upper and lower case)</span></span>
331331
<span id="cb1-24"><a href="#cb1-24" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
332332
</div>
333333
<div class="callout callout-style-default callout-tip callout-titled">
@@ -347,7 +347,7 @@ <h1>Decoding secret messages with methods</h1>
347347
<section id="classifying-temperatures" class="level1">
348348
<h1>Classifying temperatures</h1>
349349
<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>
350-
<div id="731fe794" class="cell" data-execution_count="2">
350+
<div id="c9339acc" class="cell" data-execution_count="2">
351351
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Use if-elif-else statements to classify the temperature</span></span>
352352
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Below 0: "Freezing"</span></span>
353353
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="co"># 0-10: "Cold"</span></span>
@@ -369,40 +369,41 @@ <h1>Classifying temperatures</h1>
369369
<section id="number-guessing-game" class="level1">
370370
<h1>Number guessing game</h1>
371371
<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>
372-
<div id="5401b6ad" class="cell" data-execution_count="3">
372+
<div id="ca9934a1" class="cell" data-execution_count="3">
373373
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="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>
374374
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Start by asking for their names. Then, ask the game master to input the secret number between 1 and 20. </span></span>
375-
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Make sure, that the number is not printed! Then, ask the player to guess the number. </span></span>
375+
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="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>
376376
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="co"># If the guess is too high or too low, provide feedback in order to help the player and let the player guess again. </span></span>
377377
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="co"># If the guess is correct, congratulate the player and end the game.</span></span>
378378
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
379379
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="co"># a) </span><span class="al">TODO</span><span class="co">: Your task list in more detail:</span></span>
380380
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="co"># - Ask for the names of the game master and the player</span></span>
381381
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="co"># - Implement the main game loop using a while loop</span></span>
382382
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a><span class="co"># - Ask the game master for the secret number from 1-20</span></span>
383-
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="co"># - Ask the player for a guess</span></span>
384-
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="co"># - Compare the guess to the secret number</span></span>
385-
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a><span class="co"># - Provide feedback (too high, too low, or correct)</span></span>
386-
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a><span class="co"># - Keep track of the number of guesses</span></span>
387-
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a><span class="co"># - End the game when the correct number is guessed</span></span>
388-
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a><span class="co"># - Print a congratulatory message with the number of guesses taken</span></span>
389-
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
390-
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a></span>
391-
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a><span class="co"># b) </span><span class="al">TODO</span><span class="co">: Add a feature to allow both players to play again, this time switching the roles with the game master. </span></span>
392-
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a><span class="co"># If the player wants to play again, the game should reset and the player should be able to play again, entering a new secret number to guess for the former game master. </span></span>
393-
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a><span class="co"># If the player does not want to play again, the game should end. Hint: Make sure to inform the players about the new game master using their stated names.</span></span>
394-
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
395-
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a></span>
396-
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a><span class="co"># c) </span><span class="al">TODO</span><span class="co">: Bonus Task - Enhance the game by adding difficulty levels</span></span>
397-
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a><span class="co"># Implement three difficulty levels: Easy (1-10), Medium (1-20), and Hard (1-30)</span></span>
398-
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a><span class="co"># Ask the game master to choose a difficulty level before entering the secret number</span></span>
399-
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a><span class="co"># Adjust the range of possible numbers based on the chosen difficulty</span></span>
400-
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a><span class="co"># Provide a different number of allowed guesses for each difficulty level:</span></span>
401-
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true" tabindex="-1"></a><span class="co"># - Easy: 5 guesses</span></span>
402-
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true" tabindex="-1"></a><span class="co"># - Medium: 10 guesses</span></span>
403-
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true" tabindex="-1"></a><span class="co"># - Hard: 15 guesses</span></span>
404-
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true" tabindex="-1"></a><span class="co"># If the player doesn't guess the number within the allowed guesses, end the game and reveal the secret number</span></span>
405-
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
383+
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="co"># - Hint: Use `print("\n" * 25)` to add 25 new lines</span></span>
384+
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="co"># - Ask the player for a guess</span></span>
385+
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a><span class="co"># - Compare the guess to the secret number</span></span>
386+
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a><span class="co"># - Provide feedback (too high, too low, or correct)</span></span>
387+
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a><span class="co"># - Keep track of the number of guesses</span></span>
388+
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a><span class="co"># - End the game when the correct number is guessed</span></span>
389+
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a><span class="co"># - Print a congratulatory message with the number of guesses taken</span></span>
390+
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
391+
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a></span>
392+
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a><span class="co"># b) </span><span class="al">TODO</span><span class="co">: Add a feature to allow both players to play again, this time switching the roles with the game master. </span></span>
393+
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a><span class="co"># If the player wants to play again, the game should reset and the player should be able to play again, entering a new secret number to guess for the former game master. </span></span>
394+
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a><span class="co"># If the player does not want to play again, the game should end. Hint: Make sure to inform the players about the new game master using their stated names.</span></span>
395+
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
396+
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a></span>
397+
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a><span class="co"># c) </span><span class="al">TODO</span><span class="co">: Bonus Task - Enhance the game by adding difficulty levels</span></span>
398+
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a><span class="co"># Implement three difficulty levels: Easy (1-10), Medium (1-20), and Hard (1-30)</span></span>
399+
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a><span class="co"># Ask the game master to choose a difficulty level before entering the secret number</span></span>
400+
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a><span class="co"># Adjust the range of possible numbers based on the chosen difficulty</span></span>
401+
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true" tabindex="-1"></a><span class="co"># Provide a different number of allowed guesses for each difficulty level:</span></span>
402+
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true" tabindex="-1"></a><span class="co"># - Easy: 5 guesses</span></span>
403+
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true" tabindex="-1"></a><span class="co"># - Medium: 10 guesses</span></span>
404+
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true" tabindex="-1"></a><span class="co"># - Hard: 15 guesses</span></span>
405+
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true" tabindex="-1"></a><span class="co"># If the player doesn't guess the number within the allowed guesses, end the game and reveal the secret number</span></span>
406+
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
406407
</div>
407408
</section>
408409
<section id="thats-it" class="level1">

docs/part-02/tutorial-control.pdf

295 Bytes
Binary file not shown.

docs/part-03/lecture-functions.pdf

0 Bytes
Binary file not shown.

docs/part-03/tutorial-functions.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ <h1>Introduction</h1>
304304
<section id="small-functions-for-various-tasks" class="level1">
305305
<h1>Small Functions for various tasks</h1>
306306
<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>
307-
<div id="0d1ce07e" class="cell" data-execution_count="2">
307+
<div id="3cb853f7" class="cell" data-execution_count="1">
308308
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># a) </span><span class="al">TODO</span><span class="co">: Write a function that takes two numbers as input and returns their squared sum.</span></span>
309309
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
310310
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a></span>
@@ -337,7 +337,7 @@ <h1>Small Functions for various tasks</h1>
337337
<section id="different-classes-for-different-tasks" class="level1">
338338
<h1>Different classes for different tasks</h1>
339339
<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>
340-
<div id="dcf17774" class="cell" data-execution_count="3">
340+
<div id="07750367" class="cell" data-execution_count="2">
341341
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co"># a) # </span><span class="al">TODO</span><span class="co">: Create a class called 'Book' with the following specifications:</span></span>
342342
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="co"># - It should have attributes for 'title', 'author', and 'pages'</span></span>
343343
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="co"># - Include a method called 'display_info' that prints all the book's information</span></span>
@@ -363,10 +363,11 @@ <h1>Different classes for different tasks</h1>
363363
<section id="rebuild-the-number-guessing-game" class="level1">
364364
<h1>Rebuild the number guessing game</h1>
365365
<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>
366-
<div id="4797b8a2" class="cell" data-execution_count="4">
366+
<div id="7552d01c" class="cell" data-execution_count="3">
367367
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Start by looking at your code from the previous tutorial and think about the different steps that you implemented. </span></span>
368-
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Then, 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-
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
368+
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="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+
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="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+
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
370371
</div>
371372
</section>
372373
<section id="section" class="level1">
318 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)