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 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>
<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) Concatenation</span></span>
280
-
<spanid="cb1-2"><ahref="#cb1-2" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Concatenate "Python" and " is fun!" in the 'text' variable</span></span>
280
+
<spanid="cb1-2"><ahref="#cb1-2" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Concatenate "Coffee" and " is fun!" in the 'text' variable</span></span>
281
281
<spanid="cb1-3"><ahref="#cb1-3" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Print the result</span></span>
282
282
<spanid="cb1-4"><ahref="#cb1-4" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Your code here</span></span>
<spanid="cb1-6"><ahref="#cb1-6" aria-hidden="true" tabindex="-1"></a><spanclass="co"># b) Indexing</span></span>
285
-
<spanid="cb1-7"><ahref="#cb1-7" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Print the first and last character of 'text'</span></span>
284
+
<spanid="cb1-6"><ahref="#cb1-6" aria-hidden="true" tabindex="-1"></a><spanclass="co"># b) Length</span></span>
285
+
<spanid="cb1-7"><ahref="#cb1-7" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Print the length of 'text'</span></span>
286
286
<spanid="cb1-8"><ahref="#cb1-8" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Your code here</span></span>
<spanid="cb1-10"><ahref="#cb1-10" aria-hidden="true" tabindex="-1"></a><spanclass="co"># c) Slicing</span></span>
289
-
<spanid="cb1-11"><ahref="#cb1-11" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Print the first three characters of 'text'</span></span>
288
+
<spanid="cb1-10"><ahref="#cb1-10" aria-hidden="true" tabindex="-1"></a><spanclass="co"># c) Indexing</span></span>
289
+
<spanid="cb1-11"><ahref="#cb1-11" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Print the first and last character of 'text'</span></span>
290
290
<spanid="cb1-12"><ahref="#cb1-12" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Your code here</span></span>
<spanid="cb1-15"><ahref="#cb1-15" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Print the length of 'text'</span></span>
<spanid="cb1-15"><ahref="#cb1-15" aria-hidden="true" tabindex="-1"></a><spanclass="co"># </span><spanclass="al">TODO</span><spanclass="co">: Print the first three characters of 'text'</span></span>
294
294
<spanid="cb1-16"><ahref="#cb1-16" aria-hidden="true" tabindex="-1"></a><spanclass="co"># Your code here</span></span>
<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>
<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>
<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>
<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>
0 commit comments