Skip to content

Commit f0fd9a4

Browse files
added format specifier
1 parent 609add2 commit f0fd9a4

19 files changed

+43
-23
lines changed

docs/part-01/lecture-introduction.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ <h2 class="anchored" data-anchor-id="type-conversion">Type Conversion</h2>
12011201
<li>Integer: <code>int(input())</code></li>
12021202
<li>Float: <code>float(input())</code></li>
12031203
<li>Boolean: <code>bool(input())</code></li>
1204+
<li>String: <code>str(input())</code></li>
12041205
</ol>
12051206
<p>. . .</p>
12061207
<div id="6b3ce9b1" class="cell" data-execution_count="28">
127 Bytes
Binary file not shown.

docs/part-01/lecture-presentation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,7 @@ <h2>Type Conversion</h2>
13501350
<li>Integer: <code>int(input())</code></li>
13511351
<li>Float: <code>float(input())</code></li>
13521352
<li>Boolean: <code>bool(input())</code></li>
1353+
<li>String: <code>str(input())</code></li>
13531354
</ol>
13541355
<div class="fragment">
13551356
<div id="dd14cf0c" class="cell" data-execution_count="28">

docs/part-01/tutorial-introduction.html

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,22 @@ <h2 class="anchored" data-anchor-id="tutorials-vs-assignments">Tutorials vs Assi
275275
<section id="basic-string-operations" class="level1">
276276
<h1>Basic String Operations</h1>
277277
<p>In this exercise, we’ll explore basic string operations in Python. Strings are one of the most common data types in programming, and Python provides a variety of ways to manipulate them. We’ll practice concatenation (joining strings together), indexing (accessing individual characters), slicing (extracting portions of a string), finding the length of a string, and string repetition.</p>
278-
<div id="1c73ffbb" class="cell" data-execution_count="1">
278+
<div id="c0a5b61d" class="cell" data-execution_count="2">
279279
<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) Concatenation</span></span>
280-
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Concatenate "Python" and " is fun!" in the 'text' variable</span></span>
280+
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Concatenate "Coffee" and " is fun!" in the 'text' variable</span></span>
281281
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Print the result</span></span>
282282
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
283283
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a></span>
284-
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="co"># b) Indexing</span></span>
285-
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Print the first and last character of 'text'</span></span>
284+
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="co"># b) Length</span></span>
285+
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Print the length of 'text'</span></span>
286286
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
287287
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a></span>
288-
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="co"># c) Slicing</span></span>
289-
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Print the first three characters of 'text'</span></span>
288+
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="co"># c) Indexing</span></span>
289+
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Print the first and last character of 'text'</span></span>
290290
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
291291
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a></span>
292-
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a><span class="co"># d) Length</span></span>
293-
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Print the length of 'text'</span></span>
292+
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a><span class="co"># d) Slicing</span></span>
293+
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Print the first three characters of 'text'</span></span>
294294
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a><span class="co"># Your code here</span></span>
295295
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a></span>
296296
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a><span class="co"># e) Repetition</span></span>
@@ -301,7 +301,20 @@ <h1>Basic String Operations</h1>
301301
<section id="formatted-output" class="level1">
302302
<h1>Formatted Output</h1>
303303
<p>In this exercise, we’ll practice using formatted output in Python. Formatted output allows us to present information in a structured and visually appealing way. We’ll use f-strings (formatted string literals) to create a simple receipt for a coffee shop purchase. This exercise will help you understand how to align text, format numbers, and create a clean, readable output.</p>
304-
<div id="c85e5dc9" class="cell" data-execution_count="2">
304+
<div class="callout callout-style-default callout-tip callout-titled">
305+
<div class="callout-header d-flex align-content-center">
306+
<div class="callout-icon-container">
307+
<i class="callout-icon"></i>
308+
</div>
309+
<div class="callout-title-container flex-fill">
310+
Tip
311+
</div>
312+
</div>
313+
<div class="callout-body-container callout-body">
314+
<p>Use the <code>f-string</code> method to format the output. New is the <code>f"{your_variable:.2f}"</code> syntax, which you need to format the variable to two decimal places.</p>
315+
</div>
316+
</div>
317+
<div id="b01cc1e2" class="cell" data-execution_count="3">
305318
<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"># </span><span class="al">TODO</span><span class="co">: Create a receipt for a coffee shop purchase</span></span>
306319
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Use the following information:</span></span>
307320
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>item1 <span class="op">=</span> <span class="st">"Cappuccino"</span></span>
@@ -343,7 +356,7 @@ <h1>Formatted Output</h1>
343356
<section id="arithmetic-operations" class="level1">
344357
<h1>Arithmetic Operations</h1>
345358
<p>In this exercise, we’ll practice using arithmetic operations in Python to solve several real-world problems. These calculations will help you understand how to apply basic mathematical operations in programming and how to use variables to store and manipulate numerical data. We’ll cover temperature conversion, geometric calculations, financial computations, and time calculations.</p>
346-
<div id="9e3ee0f4" class="cell" data-execution_count="3">
359+
<div id="acd5d803" class="cell" data-execution_count="4">
347360
<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"># a) Temperature Converter</span></span>
348361
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Convert 98.6°Fahrenheit to Celsius</span></span>
349362
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Formula: (°F - 32) * 5/9</span></span>
@@ -373,7 +386,7 @@ <h1>Arithmetic Operations</h1>
373386
<section id="bmi-calculator" class="level1">
374387
<h1>BMI Calculator</h1>
375388
<p>In this exercise, we’ll create a simple Body Mass Index (BMI) calculator. BMI is a measure that uses your height and weight to work out if your weight is healthy (although it has its limitations). The BMI is calculated by dividing a person’s weight (in kilograms) by the square of their height (in meters). This exercise will reinforce your understanding of arithmetic operations, user input, and string formatting while introducing you to a real-world health metric calculation.</p>
376-
<div id="18dd2d2a" class="cell" data-execution_count="4">
389+
<div id="97223d61" class="cell" data-execution_count="5">
377390
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co"># </span><span class="al">TODO</span><span class="co">: Implement a BMI calculator</span></span>
378391
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Ask for weight in kg</span></span>
379392
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Ask for height in meters</span></span>
2.2 KB
Binary file not shown.

docs/part-02/lecture-control.pdf

-7 Bytes
Binary file not shown.

docs/part-02/tutorial-control.pdf

-2 Bytes
Binary file not shown.

docs/part-03/lecture-functions.pdf

0 Bytes
Binary file not shown.
2 Bytes
Binary file not shown.

docs/part-05/lecture-errors.pdf

3 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)