<?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>Python &#8211; sekol.ninja</title>
	<atom:link href="https://sekol.ninja/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>https://sekol.ninja</link>
	<description></description>
	<lastBuildDate>Wed, 10 Jun 2026 13:43:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<item>
		<title>Build Your Own AI-Powered Choose Your Own Adventure</title>
		<link>https://sekol.ninja/build-your-own-ai-powered-choose-your-own-adventure/</link>
		
		<dc:creator><![CDATA[Michael Sekol]]></dc:creator>
		<pubDate>Wed, 10 Jun 2026 12:02:53 +0000</pubDate>
				<category><![CDATA[Learning to Code]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[ChatGPT]]></category>
		<category><![CDATA[Choose your own adventure]]></category>
		<category><![CDATA[Learn to Code]]></category>
		<category><![CDATA[Summer Camp]]></category>
		<guid isPermaLink="false">https://sekol.ninja/?p=10640</guid>

					<description><![CDATA[A Step-by-Step Python Guide for Beginners In this project, you will write a Python program that uses real artificial intelligence (ChatGPT) to [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">A Step-by-Step Python Guide for Beginners</h3>



<p class="wp-block-paragraph">In this project, you will write a Python program that uses real artificial intelligence</p>



<p class="wp-block-paragraph">(ChatGPT) to create a story that changes based on YOUR choices.</p>



<p class="wp-block-paragraph">Every time you play, the story will be different!</p>



<p class="wp-block-paragraph"><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-global-color-2-color">No coding experience needed — just follow the steps!</mark></p>



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
  /* Reset for WordPress compatibility */
  .adventure-guide * { box-sizing: border-box !important; }
  .adventure-guide {
    font-family: 'Segoe UI', Arial, sans-serif !important;
    max-width: 860px !important;
    margin: 0 auto !important;
    padding: 20px !important;
    color: #333 !important;
    line-height: 1.7 !important;
    font-size: 16px !important;
  }
  .adventure-guide h1 {
    color: #1B365D !important;
    font-size: 2em !important;
    border-bottom: 3px solid #2E75B6 !important;
    padding-bottom: 10px !important;
    margin-top: 40px !important;
    margin-bottom: 20px !important;
  }
  .adventure-guide h2 {
    color: #2E75B6 !important;
    font-size: 1.5em !important;
    margin-top: 35px !important;
    margin-bottom: 15px !important;
  }
  .adventure-guide h3 {
    color: #333 !important;
    font-size: 1.2em !important;
    margin-top: 25px !important;
    margin-bottom: 10px !important;
  }
  .adventure-guide p {
    margin: 10px 0 !important;
    line-height: 1.7 !important;
  }
  .adventure-guide .hero-section {
    text-align: center !important;
    padding: 40px 20px !important;
    margin-bottom: 30px !important;
    background: linear-gradient(135deg, #1B365D, #2E75B6) !important;
    color: white !important;
    border-radius: 12px !important;
  }
  .adventure-guide .hero-section h1 {
    color: white !important;
    border-bottom: none !important;
    font-size: 2.2em !important;
    margin: 0 0 10px 0 !important;
  }
  .adventure-guide .hero-section p {
    color: rgba(255,255,255,0.9) !important;
    font-size: 1.1em !important;
    margin: 5px 0 !important;
  }
  /* Callout boxes */
  .adventure-guide .box {
    border-radius: 8px !important;
    padding: 18px 22px !important;
    margin: 16px 0 !important;
    border-left: 5px solid #ccc !important;
  }
  .adventure-guide .box-title {
    font-weight: bold !important;
    margin-bottom: 8px !important;
    color: #1B365D !important;
    font-size: 1.05em !important;
  }
  .adventure-guide .box-purple {
    background-color: #F3E5F5 !important;
    border-left-color: #9C27B0 !important;
  }
  .adventure-guide .box-green {
    background-color: #E8F5E9 !important;
    border-left-color: #4CAF50 !important;
  }
  .adventure-guide .box-orange {
    background-color: #FFF3E0 !important;
    border-left-color: #FF9800 !important;
  }
  .adventure-guide .box-red {
    background-color: #FFEBEE !important;
    border-left-color: #F44336 !important;
  }
  .adventure-guide .box-teal {
    background-color: #E0F7FA !important;
    border-left-color: #00BCD4 !important;
  }
  .adventure-guide .box-blue {
    background-color: #E8F0FE !important;
    border-left-color: #2E75B6 !important;
  }
  /* Code blocks */
  .adventure-guide pre {
    background-color: #1E1E1E !important;
    color: #D4D4D4 !important;
    border-radius: 8px !important;
    padding: 18px 22px !important;
    margin: 16px 0 !important;
    overflow-x: auto !important;
    font-family: 'Courier New', monospace !important;
    font-size: 14px !important;
    line-height: 1.6 !important;
    border: 1px solid #333 !important;
  }
  .adventure-guide pre .comment { color: #6A9955 !important; }
  .adventure-guide pre .string { color: #CE9178 !important; }
  .adventure-guide pre .keyword { color: #569CD6 !important; }
  .adventure-guide pre .function { color: #DCDCAA !important; }
  .adventure-guide pre .number { color: #B5CEA8 !important; }
  /* Inline code */
  .adventure-guide code {
    background-color: #f0f0f0 !important;
    color: #333 !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    font-family: 'Courier New', monospace !important;
    font-size: 0.9em !important;
  }
  .adventure-guide pre code {
    background: none !important;
    color: inherit !important;
    padding: 0 !important;
    border-radius: 0 !important;
    font-size: inherit !important;
  }
  /* Terminal commands */
  .adventure-guide .terminal-cmd {
    background-color: #E8F5E9 !important;
    border-left: 5px solid #4CAF50 !important;
    padding: 12px 18px !important;
    border-radius: 8px !important;
    margin: 12px 0 !important;
    font-family: 'Courier New', monospace !important;
    font-size: 15px !important;
    color: #333 !important;
  }
  /* Step headers */
  .adventure-guide .step-header {
    display: flex !important;
    align-items: baseline !important;
    gap: 10px !important;
    margin-top: 35px !important;
    margin-bottom: 15px !important;
    padding-bottom: 8px !important;
    border-bottom: 2px solid #E8F0FE !important;
  }
  .adventure-guide .step-num {
    color: #2E75B6 !important;
    font-size: 1.6em !important;
    font-weight: bold !important;
    white-space: nowrap !important;
  }
  .adventure-guide .step-title {
    color: #1B365D !important;
    font-size: 1.6em !important;
    font-weight: bold !important;
  }
  /* Color key grid */
  .adventure-guide .color-key {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
    margin: 20px 0 !important;
  }
  @media (max-width: 600px) {
    .adventure-guide .color-key { grid-template-columns: 1fr !important; }
    .adventure-guide .step-header { flex-direction: column !important; gap: 2px !important; }
  }
  .adventure-guide .color-key .box { margin: 0 !important; }
  /* Table */
  .adventure-guide table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 16px 0 !important;
    font-size: 0.95em !important;
  }
  .adventure-guide th {
    background-color: #1B365D !important;
    color: white !important;
    padding: 10px 14px !important;
    text-align: left !important;
    font-weight: bold !important;
  }
  .adventure-guide td {
    padding: 10px 14px !important;
    border: 1px solid #ddd !important;
    vertical-align: top !important;
  }
  .adventure-guide tr:nth-child(even) td { background-color: #f5f8ff !important; }
  .adventure-guide ul { margin: 8px 0 !important; padding-left: 24px !important; }
  .adventure-guide li { margin: 4px 0 !important; }
  .adventure-guide a { color: #2E75B6 !important; }
</style>
</head>
<body>
<div class="adventure-guide">

<!-- HERO -->
<div class="hero-section">
  <h1>In this project, you will write a Python program that uses real artificial intelligence (ChatGPT) to create a story that changes based on <strong>your</strong> choices. Every time you play, the story will be different!</h1>
  <p style="margin-top: 15px !important; font-style: italic !important; opacity: 0.85 !important;"></p>
</div>

<!-- COLOR KEY -->
<h1>How to Read This Guide</h1>
<p>This guide uses color-coded boxes to help you know what you&#8217;re looking at:</p>

<div class="color-key">
  <div class="box box-purple"><div class="box-title">🟣 PURPLE — New Vocabulary</div>Explains new words or concepts.</div>
  <div class="box box-green"><div class="box-title">🟢 GREEN — Terminal Commands</div>Commands for the terminal, NOT Thonny.</div>
  <div class="box box-orange"><div class="box-title">🟠 ORANGE — Tips &#038; Hints</div>Helpful tips and suggestions.</div>
  <div class="box box-red"><div class="box-title">🔴 RED — Warnings &#038; Mistakes</div>Common errors and how to fix them.</div>
</div>
<div class="color-key" style="margin-top: 0 !important;">
  <div class="box box-teal"><div class="box-title">🟦 TEAL — Expected Output</div>What you should see on screen.</div>
  <div class="box" style="background: #1E1E1E !important; border-left-color: #555 !important; color: #D4D4D4 !important;"><div class="box-title" style="color: #D4D4D4 !important;">⬛ DARK — Code to Type</div>Type this exactly into Thonny.</div>
</div>

<!-- WHAT YOU NEED -->
<h1>What You Need Before Starting</h1>
<ul>
  <li><strong>A Raspberry Pi</strong> that is turned on, connected to a monitor, keyboard, mouse, and the internet (Wi-Fi).</li>
  <li><strong>Thonny</strong> — the program where you write your code. It&#8217;s already installed on every Raspberry Pi. Look for a blue and white icon on the desktop or in the menu under <strong>Programming</strong>.</li>
  <li><strong>An API key</strong> — a special password that lets your program talk to ChatGPT. You&#8217;ll copy and paste it from <a href="https://www.sekol.ninja" target="_blank">www.sekol.ninja</a>.</li>
</ul>

<div class="box box-purple">
  <div class="box-title">🟣 New Vocabulary: What is an API Key?</div>
  <p>An <strong>API key</strong> is like a special password that lets one computer program talk to another. In this project, your Python program needs to talk to ChatGPT (which lives on the internet). The API key proves to ChatGPT that you have permission to use it.</p>
  <p>Think of it like a library card — the library (ChatGPT) won&#8217;t let you borrow books (get AI responses) unless you show your card (API key).</p>
</div>

<!-- STEP 1 -->
<div class="step-header"><span class="step-num">Step 1:</span><span class="step-title">Open the Terminal</span></div>

<p>First, we need to install a small piece of software that lets Python talk to ChatGPT. To do this, we&#8217;ll use the <strong>terminal</strong> — the black window where you type commands directly to the computer.</p>
<p>Click the <strong>black rectangle icon</strong> in the top taskbar of your Raspberry Pi. A black window with a blinking cursor should open.</p>

<div class="box box-purple">
  <div class="box-title">🟣 New Vocabulary: What is the Terminal?</div>
  <p>The <strong>terminal</strong> (also called the &#8220;command line&#8221;) is a way to talk to your computer by typing text commands instead of clicking buttons. It&#8217;s what hackers use in movies! But in real life, it&#8217;s just a tool that programmers and cybersecurity experts use every day.</p>
</div>

<!-- STEP 2 -->
<div class="step-header"><span class="step-num">Step 2:</span><span class="step-title">Install the OpenAI Library</span></div>

<p>Type the following command into the terminal and press <strong>Enter</strong>:</p>
<div class="terminal-cmd">pip install openai</div>
<p>Wait for it to finish. You&#8217;ll see some text scroll by as it downloads and installs. When you see the blinking cursor again, it&#8217;s done.</p>

<div class="box box-purple">
  <div class="box-title">🟣 New Vocabulary: What is a Library?</div>
  <p>A <strong>library</strong> (in coding) is a bundle of pre-written code that someone else made for you. Instead of writing hundreds of lines of code to connect to ChatGPT yourself, you just install the <code>openai</code> library and it handles all the complicated stuff. Think of it like using a recipe from a cookbook instead of inventing a dish from scratch.</p>
</div>

<div class="box box-red">
  <div class="box-title">🔴 If You See an Error</div>
  <p>If you see a red error message, try this command instead:</p>
  <div class="terminal-cmd" style="background-color: #ffcdd2 !important; border-left-color: #c62828 !important;">pip install openai &#8211;break-system-packages</div>
  <p>This is a Raspberry Pi-specific thing. It&#8217;s safe and normal.</p>
</div>

<!-- STEP 3 -->
<div class="step-header"><span class="step-num">Step 3:</span><span class="step-title">Open Thonny and Create a New File</span></div>

<p>Now close the terminal (type <code>exit</code> or click the X). Open <strong>Thonny</strong> by clicking its icon (blue and white logo) on the desktop, or find it in the Raspberry Pi menu under <strong>Programming → Thonny</strong>.</p>
<p>When Thonny opens, you&#8217;ll see two sections:</p>
<ul>
  <li><strong>Top section</strong> — this is where you write your code (the &#8220;editor&#8221;)</li>
  <li><strong>Bottom section</strong> — this is where your program&#8217;s output appears (the &#8220;shell&#8221;)</li>
</ul>
<p>Click <strong>File → Save As</strong>. Name your file <code>adventure.py</code> and save it to the Desktop.</p>

<div class="box box-red">
  <div class="box-title">🔴 Important: The File Name Must End in .py</div>
  <p>Python files always end in <code>.py</code> — this tells the computer it&#8217;s a Python program. Make sure you type <code>adventure.py</code> (not just <code>adventure</code>).</p>
</div>

<!-- STEP 4 -->
<div class="step-header"><span class="step-num">Step 4:</span><span class="step-title">Import the Library</span></div>

<p>Now we start writing code! In the <strong>top section</strong> of Thonny (the editor), type the following:</p>

<pre><code><span class="comment"># ============================================</span>
<span class="comment"># CHOOSE YOUR OWN ADVENTURE</span>
<span class="comment"># Powered by AI (ChatGPT)</span>
<span class="comment"># ============================================</span>

<span class="comment"># Import the library we need</span>
<span class="keyword">from</span> openai <span class="keyword">import</span> OpenAI</code></pre>

<div class="box box-purple">
  <div class="box-title">🟣 What Does This Code Do?</div>
  <p>Lines that start with <code>#</code> are called <strong>comments</strong>. The computer completely ignores them. They&#8217;re notes for humans reading the code.</p>
  <p>The line <code>from openai import OpenAI</code> tells Python: &#8220;Go find the openai library we installed, and bring in the tool called OpenAI so we can use it.&#8221;</p>
</div>

<!-- STEP 5 -->
<div class="step-header"><span class="step-num">Step 5:</span><span class="step-title">Connect to ChatGPT</span></div>

<p>Press <strong>Enter</strong> twice after the last line (to leave a blank line), then type:</p>

<pre><code><span class="comment"># Set up the connection to ChatGPT</span>
<span class="comment"># Get your API key from www.sekol.ninja</span>
client = OpenAI(api_key=<span class="string">"paste-your-api-key-here"</span>)</code></pre>

<div class="box box-orange">
  <div class="box-title">❗ Getting Your API Key</div>
  <p>You need to replace <code>paste-your-api-key-here</code> with a real API key.</p>
  <p><strong>Go to <a href="https://www.sekol.ninja" target="_blank">www.sekol.ninja</a> in your web browser and copy the API key from the page.</strong></p>
  <p>Then come back to Thonny and paste it between the quotation marks. It will look something like:<br>
  <code>client = OpenAI(api_key="sk-abc123xyz456...")</code></p>
  <p><strong>Keep the quotation marks!</strong> The key must be inside the quotes.</p>
</div>

<div class="box box-purple">
  <div class="box-title">🟣 What Does This Code Do?</div>
  <p>This line creates a <strong>client</strong> — think of it as a phone that can call ChatGPT. The API key is like the phone number. Without it, you can&#8217;t make the call.</p>
</div>

<!-- STEP 6 -->
<div class="step-header"><span class="step-num">Step 6:</span><span class="step-title">Give the AI Its Personality</span></div>

<p>This is the fun part! We&#8217;re going to tell ChatGPT what kind of storyteller it should be. Add this code below what you already have:</p>

<pre><code><span class="comment"># Tell the AI what kind of stories to create</span>
system_message = {
    <span class="string">"role"</span>: <span class="string">"system"</span>,
    <span class="string">"content"</span>: <span class="string">"""You are an adventure story master for kids.
You create exciting choose-your-own-adventure stories.

RULES:
- Keep the story fun, exciting, and kid-friendly.
- Each response should be 2-3 short paragraphs.
- Always end with exactly 3 numbered choices for what to do next.
- Use vivid descriptions to make the story come alive.
- The story should have a sci-fi space adventure theme.
- Never include anything scary, violent, or inappropriate."""</span>
}</code></pre>

<div class="box box-purple">
  <div class="box-title">🟣 What Does This Code Do?</div>
  <p>This creates a <strong>system message</strong> — it&#8217;s like a set of instructions you whisper to ChatGPT before the conversation starts. The player never sees this, but it controls HOW the AI tells the story.</p>
  <p><code>"role": "system"</code> tells ChatGPT &#8220;these are your instructions, not something the user said.&#8221;</p>
  <p>The three quotation marks <code>"""</code> let you write a message that spans multiple lines.</p>
</div>

<div class="box box-orange">
  <div class="box-title">🟠 Customize the Theme!</div>
  <p>Want a fantasy adventure instead of sci-fi? A mystery? A pirate story? Change the RULES section to whatever you want! This is YOUR story engine.</p>
</div>

<!-- STEP 7 -->
<div class="step-header"><span class="step-num">Step 7:</span><span class="step-title">Create the Conversation History</span></div>

<p>Add this line below the system message:</p>

<pre><code><span class="comment"># Create a list to keep track of the conversation</span>
conversation = [system_message]</code></pre>

<div class="box box-purple">
  <div class="box-title">🟣 What Does This Code Do?</div>
  <p>ChatGPT doesn&#8217;t have a memory on its own. Every time you send it a message, you have to send the <strong>entire conversation so far</strong>. This list called <code>conversation</code> stores every message — both yours and the AI&#8217;s.</p>
  <p>Right now it only contains the system message. As the game goes on, we&#8217;ll add more messages to this list.</p>
</div>

<!-- STEP 8 -->
<div class="step-header"><span class="step-num">Step 8:</span><span class="step-title">Create the Welcome Screen</span></div>

<p>Add a welcome screen that the player sees when they start:</p>

<pre><code><span class="comment"># Print the welcome screen</span>
<span class="function">print</span>(<span class="string">"="</span> * <span class="number">50</span>)
<span class="function">print</span>(<span class="string">"  CHOOSE YOUR OWN ADVENTURE"</span>)
<span class="function">print</span>(<span class="string">"  Powered by AI"</span>)
<span class="function">print</span>(<span class="string">"="</span> * <span class="number">50</span>)
<span class="function">print</span>()</code></pre>

<div class="box box-purple">
  <div class="box-title">🟣 What Does This Code Do?</div>
  <p><code>print()</code> displays text on the screen. <code>"=" * 50</code> means &#8220;repeat the = sign 50 times&#8221; — it makes a nice decorative line. <code>print()</code> with nothing inside prints a blank line for spacing.</p>
</div>

<!-- STEP 9 -->
<div class="step-header"><span class="step-num">Step 9:</span><span class="step-title">Ask for the Player&#8217;s Name</span></div>

<pre><code><span class="comment"># Ask the player for their name</span>
player_name = <span class="function">input</span>(<span class="string">"Enter your character's name: "</span>)
<span class="function">print</span>()
<span class="function">print</span>(<span class="string">"Welcome, "</span> + player_name + <span class="string">"! Your adventure begins..."</span>)
<span class="function">print</span>()</code></pre>

<div class="box box-purple">
  <div class="box-title">🟣 What Does This Code Do?</div>
  <p><code>input()</code> pauses the program and waits for the player to type something. Whatever they type gets stored in <code>player_name</code>.</p>
  <p>The <code>+</code> sign connects pieces of text together. So if the player types &#8220;Luna&#8221;, it prints: <em>Welcome, Luna! Your adventure begins&#8230;</em></p>
</div>

<!-- STEP 10 -->
<div class="step-header"><span class="step-num">Step 10:</span><span class="step-title">Send the First Message</span></div>

<pre><code><span class="comment"># Create the first message to start the story</span>
first_message = {
    <span class="string">"role"</span>: <span class="string">"user"</span>,
    <span class="string">"content"</span>: <span class="string">"Start a new adventure story. My character's name is "</span> + player_name + <span class="string">". Begin the story!"</span>
}
conversation.append(first_message)</code></pre>

<div class="box box-purple">
  <div class="box-title">🟣 What Does This Code Do?</div>
  <p>This creates a message with <code>"role": "user"</code> — meaning it&#8217;s FROM the player TO the AI.</p>
  <p><code>.append()</code> means &#8220;add to the end of the list.&#8221; Now our <code>conversation</code> list has two items: the system message AND this first user message.</p>
</div>

<!-- STEP 11 -->
<div class="step-header"><span class="step-num">Step 11:</span><span class="step-title">Build the Game Loop</span></div>

<p>This is the biggest section — the engine that makes the whole game run. It&#8217;s a <strong>loop</strong> that keeps going: send a message to ChatGPT → show the story → ask the player → repeat.</p>

<p><strong>⚠️ Indentation (the spaces at the beginning of lines) is very important in Python.</strong> Everything inside the loop must be indented with 4 spaces. Thonny should add the spaces automatically when you press Enter after a line ending with <code>:</code></p>

<pre><code><span class="comment"># The game loop</span>
<span class="keyword">while</span> True:
    <span class="comment"># Send the conversation to ChatGPT</span>
    response = client.chat.completions.create(
        model=<span class="string">"gpt-4o-mini"</span>,
        messages=conversation
    )

    <span class="comment"># Get the AI's story text</span>
    story_text = response.choices[<span class="number">0</span>].message.content

    <span class="comment"># Save the response to conversation history</span>
    conversation.append({
        <span class="string">"role"</span>: <span class="string">"assistant"</span>,
        <span class="string">"content"</span>: story_text
    })

    <span class="comment"># Display the story</span>
    <span class="function">print</span>(story_text)
    <span class="function">print</span>()

    <span class="comment"># Ask what the player wants to do</span>
    choice = <span class="function">input</span>(<span class="string">"What do you choose? (1, 2, 3, or 'quit'): "</span>)

    <span class="comment"># If they type quit, end the game</span>
    <span class="keyword">if</span> choice.lower() == <span class="string">"quit"</span>:
        <span class="function">print</span>()
        <span class="function">print</span>(<span class="string">"Thanks for playing, "</span> + player_name + <span class="string">"!"</span>)
        <span class="function">print</span>(<span class="string">"May the Code be with you!"</span>)
        <span class="keyword">break</span>

    <span class="comment"># Send the player's choice to the AI</span>
    conversation.append({
        <span class="string">"role"</span>: <span class="string">"user"</span>,
        <span class="string">"content"</span>: <span class="string">"I choose option "</span> + choice
    })

    <span class="function">print</span>()
    <span class="function">print</span>(<span class="string">"Generating next chapter..."</span>)
    <span class="function">print</span>()</code></pre>

<div class="box box-purple">
  <div class="box-title">🟣 What Does This Code Do? (Section by Section)</div>
  <p><strong>while True:</strong> — Creates a loop that runs forever (until we stop it). Each cycle = one &#8220;turn&#8221; of the adventure.</p>
  <p><strong>client.chat.completions.create(&#8230;)</strong> — This is the line that actually calls ChatGPT! It sends the entire conversation and gets back a response.</p>
  <p><strong>response.choices[0].message.content</strong> — The AI&#8217;s response comes in a structured package. This pulls out just the story text.</p>
  <p><strong>conversation.append(&#8230;)</strong> — Saves the AI&#8217;s response to our conversation list so it remembers what happened.</p>
  <p><strong>input(&#8230;)</strong> — Pauses and waits for the player to type their choice.</p>
  <p><strong>if choice.lower() == &#8220;quit&#8221;:</strong> — Checks if the player typed &#8220;quit&#8221; (or &#8220;QUIT&#8221; or &#8220;Quit&#8221; — <code>.lower()</code> converts it to lowercase first).</p>
  <p><strong>break</strong> — Stops the loop and ends the game.</p>
</div>

<div class="box box-red">
  <div class="box-title">🔴 Watch the Indentation!</div>
  <p>Every line inside the <code>while True:</code> loop must start with <strong>4 spaces</strong>. Every line inside the <code>if</code> block must start with <strong>8 spaces</strong> (4 for the loop + 4 for the if).</p>
  <p>If you see <code>IndentationError</code>, check that every line has the right number of spaces. Thonny usually handles this automatically, but if you&#8217;ve been copying and pasting, the spacing might be off.</p>
</div>

<!-- STEP 12 -->
<div class="step-header"><span class="step-num">Step 12:</span><span class="step-title">Save and Run Your Program!</span></div>

<p>You&#8217;re done writing code! Time to test it.</p>
<ol>
  <li>Press <strong>Ctrl + S</strong> to save your file.</li>
  <li>Press the green <strong>Run ▶</strong> button at the top of Thonny (or press <strong>F5</strong>).</li>
  <li>Look at the bottom section of Thonny (the shell). You should see:</li>
</ol>

<div class="box box-teal">
<pre style="background: #E0F7FA !important; color: #333 !important; border: none !important; margin: 0 !important; padding: 0 !important;"><code style="color: #333 !important;">==================================================
  CHOOSE YOUR OWN ADVENTURE
  Powered by AI
==================================================

Enter your character's name: </code></pre>
</div>

<ol start="4">
  <li>Type a character name and press Enter. Wait a few seconds while ChatGPT generates the first chapter.</li>
  <li>Read the story! At the end, you&#8217;ll see 3 choices. Type <code>1</code>, <code>2</code>, or <code>3</code> and press Enter.</li>
  <li>When you&#8217;re done playing, type <code>quit</code> to end.</li>
</ol>

<div class="box box-orange">
  <div class="box-title">🟠 It Takes a Few Seconds!</div>
  <p>After you make a choice, the program sends your message to ChatGPT over the internet and waits for a response. This usually takes 3–10 seconds. Just be patient — the AI is writing your story!</p>
</div>

<!-- TROUBLESHOOTING -->
<h1>Troubleshooting</h1>
<p>If something goes wrong, check here first:</p>

<table>
  <thead><tr><th>Error</th><th>What to Do</th></tr></thead>
  <tbody>
    <tr><td><code>ModuleNotFoundError: No module named 'openai'</code></td><td>You skipped Step 2. Open the terminal and run: <code>pip install openai --break-system-packages</code></td></tr>
    <tr><td><code>AuthenticationError</code> or <code>Invalid API key</code></td><td>Your API key is wrong. Go back to <a href="https://www.sekol.ninja" target="_blank">www.sekol.ninja</a>, copy the key again, and make sure it&#8217;s pasted between the quotation marks. No extra spaces.</td></tr>
    <tr><td><code>IndentationError</code></td><td>Your spacing is wrong. Lines inside the while loop need 4 spaces. Lines inside the if block need 8 spaces. Delete the spaces and re-type them.</td></tr>
    <tr><td><code>SyntaxError</code></td><td>You have a typo. Check for missing quotation marks, missing colons (<code>:</code>) after <code>while True</code> and <code>if</code> statements, and missing parentheses.</td></tr>
    <tr><td>Program runs but nothing happens</td><td>It&#8217;s waiting for you to type! Look at the bottom of Thonny (the shell) for a blinking cursor.</td></tr>
    <tr><td><code>ConnectionError</code> or <code>Timeout</code></td><td>Your Pi isn&#8217;t connected to the internet. Check Wi-Fi (click the icon in the top-right).</td></tr>
    <tr><td><code>RateLimitError</code></td><td>Too many people using the key at once. Wait 30 seconds and try again.</td></tr>
  </tbody>
</table>

<!-- CUSTOMIZE -->
<h1>Make It Your Own!</h1>

<div class="box box-orange">
  <div class="box-title">🎨 Change the Story Theme</div>
  <p>Edit the system_message content (Step 6) to change what kind of stories the AI tells. Try:</p>
  <ul>
    <li>A fantasy quest with dragons and wizards</li>
    <li>A mystery detective story</li>
    <li>A pirate adventure on the high seas</li>
    <li>A zombie survival story (kid-friendly of course!)</li>
    <li>A time-travel adventure through history</li>
  </ul>
</div>

<div class="box box-orange">
  <div class="box-title">🚀 Add More Player Customization</div>
  <p>Ask the player more questions at the start:</p>
  <pre style="margin: 8px 0 !important;"><code>companion = <span class="function">input</span>(<span class="string">"Name your sidekick: "</span>)
superpower = <span class="function">input</span>(<span class="string">"What is your superpower? "</span>)</code></pre>
  <p>Then include them in the first_message content so the AI knows about them!</p>
</div>

<div class="box box-orange">
  <div class="box-title">🏆 Challenge: Add a Score System</div>
  <p>Create a variable called <code>score = 0</code> at the beginning. Modify the system message to tell the AI to include score changes in the story like &#8220;+10 points for bravery!&#8221; Then use Python to track and display the running score.</p>
</div>

<!-- COMPLETE CODE -->
<h1>Complete Code (All Together)</h1>

<p>Here is the entire program in one place. If you got lost during the steps, use this as a reference. Remember to replace <code>paste-your-api-key-here</code> with your real API key from <a href="https://www.sekol.ninja" target="_blank">www.sekol.ninja</a>.</p>

<pre><code><span class="comment"># ============================================</span>
<span class="comment"># CHOOSE YOUR OWN ADVENTURE</span>
<span class="comment"># Powered by AI (ChatGPT)</span>
<span class="comment"># ============================================</span>

<span class="comment"># Import the library we need</span>
<span class="keyword">from</span> openai <span class="keyword">import</span> OpenAI

<span class="comment"># Set up the connection to ChatGPT</span>
<span class="comment"># Get your API key from www.sekol.ninja</span>
client = OpenAI(api_key=<span class="string">"paste-your-api-key-here"</span>)

<span class="comment"># Tell the AI what kind of stories to create</span>
system_message = {
    <span class="string">"role"</span>: <span class="string">"system"</span>,
    <span class="string">"content"</span>: <span class="string">"""You are an adventure story master for kids.
You create exciting choose-your-own-adventure stories.

RULES:
- Keep the story fun, exciting, and kid-friendly.
- Each response should be 2-3 short paragraphs.
- Always end with exactly 3 numbered choices for what to do next.
- Use vivid descriptions to make the story come alive.
- The story should have a sci-fi space adventure theme.
- Never include anything scary, violent, or inappropriate."""</span>
}

<span class="comment"># Create a list to keep track of the conversation</span>
conversation = [system_message]

<span class="comment"># Print the welcome screen</span>
<span class="function">print</span>(<span class="string">"="</span> * <span class="number">50</span>)
<span class="function">print</span>(<span class="string">"  CHOOSE YOUR OWN ADVENTURE"</span>)
<span class="function">print</span>(<span class="string">"  Powered by AI"</span>)
<span class="function">print</span>(<span class="string">"="</span> * <span class="number">50</span>)
<span class="function">print</span>()

<span class="comment"># Ask the player for their name</span>
player_name = <span class="function">input</span>(<span class="string">"Enter your character's name: "</span>)
<span class="function">print</span>()
<span class="function">print</span>(<span class="string">"Welcome, "</span> + player_name + <span class="string">"! Your adventure begins..."</span>)
<span class="function">print</span>()

<span class="comment"># Create the first message to start the story</span>
first_message = {
    <span class="string">"role"</span>: <span class="string">"user"</span>,
    <span class="string">"content"</span>: <span class="string">"Start a new adventure story. My character's name is "</span> + player_name + <span class="string">". Begin the story!"</span>
}
conversation.append(first_message)

<span class="comment"># The game loop</span>
<span class="keyword">while</span> True:
    <span class="comment"># Send the conversation to ChatGPT</span>
    response = client.chat.completions.create(
        model=<span class="string">"gpt-4o-mini"</span>,
        messages=conversation
    )

    <span class="comment"># Get the AI's story text</span>
    story_text = response.choices[<span class="number">0</span>].message.content

    <span class="comment"># Save the response to conversation history</span>
    conversation.append({
        <span class="string">"role"</span>: <span class="string">"assistant"</span>,
        <span class="string">"content"</span>: story_text
    })

    <span class="comment"># Display the story</span>
    <span class="function">print</span>(story_text)
    <span class="function">print</span>()

    <span class="comment"># Ask what the player wants to do</span>
    choice = <span class="function">input</span>(<span class="string">"What do you choose? (1, 2, 3, or 'quit'): "</span>)

    <span class="comment"># If they type quit, end the game</span>
    <span class="keyword">if</span> choice.lower() == <span class="string">"quit"</span>:
        <span class="function">print</span>()
        <span class="function">print</span>(<span class="string">"Thanks for playing, "</span> + player_name + <span class="string">"!"</span>)
        <span class="function">print</span>(<span class="string">"May the Code be with you!"</span>)
        <span class="keyword">break</span>

    <span class="comment"># Send the player's choice to the AI</span>
    conversation.append({
        <span class="string">"role"</span>: <span class="string">"user"</span>,
        <span class="string">"content"</span>: <span class="string">"I choose option "</span> + choice
    })

    <span class="function">print</span>()
    <span class="function">print</span>(<span class="string">"Generating next chapter..."</span>)
    <span class="function">print</span>()</code></pre>

<div class="hero-section" style="margin-top: 40px !important; padding: 25px !important;">
  <p style="font-size: 1.3em !important; margin: 0 !important;"><em>May the Code be with you!</em></p>
</div>

</div>
</body>
</html>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Installing Visual Studio Code on a Raspberry Pi for Python Development</title>
		<link>https://sekol.ninja/installing-visual-studio-code-on-a-raspberry-pi-for-python-development/</link>
		
		<dc:creator><![CDATA[Michael Sekol]]></dc:creator>
		<pubDate>Tue, 09 Jun 2026 16:52:48 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Install on Raspberry Pi]]></category>
		<category><![CDATA[Install Software]]></category>
		<category><![CDATA[VC Code for Raspberry Pi]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<guid isPermaLink="false">https://sekol.ninja/?p=10624</guid>

					<description><![CDATA[A Beginner-Friendly, Step-by-Step Guide Introduction If you have ever opened your Raspberry Pi&#8217;s Programming menu, you probably noticed an application called Thonny [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">A Beginner-Friendly, Step-by-Step Guide</p>



<!-- ── Introduction ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Introduction</h2>

<p style="margin-bottom:1.2em !important;">If you have ever opened your Raspberry Pi&#8217;s Programming menu, you probably noticed an application called <strong>Thonny</strong> already sitting there, ready to go. Thonny is a simple Python editor that ships with Raspberry Pi OS, and for absolute beginners writing their very first lines of Python, it does the job. It has a big Run button, a built-in shell, and almost nothing else to distract you.</p>

<p style="margin-bottom:1.2em !important;">So why would you bother installing something different?</p>

<p style="margin-bottom:1.2em !important;">The short answer is that Thonny is a <em>learning tool</em>, and Visual Studio Code (VS Code) is a <em>professional development environment</em>. The gap between the two is significant, and the sooner you make the switch, the sooner you start building the habits and skills that carry over into real-world software development.</p>

<!-- ── What Is VS Code ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">What Is Visual Studio Code?</h2>

<p style="margin-bottom:1.2em !important;">Visual Studio Code is a free, open-source code editor created by Microsoft. It runs on Windows, macOS, and Linux, which means it also runs on Raspberry Pi OS (a Debian-based Linux distribution). Despite being free, it is the most popular code editor in the world, used by millions of professional developers every day.</p>

<p style="margin-bottom:1.2em !important;">VS Code is <strong>not</strong> the same thing as Visual Studio (the full IDE). Think of VS Code as a lightweight, fast editor that you can customize with extensions to support almost any programming language, framework, or workflow you can imagine. It starts small and grows with you.</p>

<!-- ── Why VS Code ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Why VS Code Instead of Thonny?</h2>

<p style="margin-bottom:1.2em !important;">Thonny was designed to teach beginners the basics of Python. That narrow focus is both its strength and its limitation. Here is what Thonny <strong>does not</strong> give you:</p>

<ul style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;"><strong>No IntelliSense or intelligent code completion.</strong> Thonny offers basic autocomplete, but it cannot predict what you need or show you function signatures and documentation as you type.</li>
<li style="margin-bottom:0.6em !important;"><strong>No built-in terminal.</strong> Professional developers run commands, install packages, and manage files from inside their editor. Thonny keeps you locked into its own shell.</li>
<li style="margin-bottom:0.6em !important;"><strong>No extension ecosystem.</strong> You cannot add Git integration, linters, formatters, database viewers, or support for other languages.</li>
<li style="margin-bottom:0.6em !important;"><strong>No multi-file project support.</strong> Real projects are made of many files organized in folders. Thonny is built around editing one file at a time.</li>
<li style="margin-bottom:0.6em !important;"><strong>No integrated debugging for complex projects.</strong> Thonny has a basic debugger, but it lacks breakpoint conditions, watch expressions, and call stack navigation.</li>
</ul>

<p style="margin-bottom:1.2em !important;">VS Code solves all of these problems and adds capabilities you didn&#8217;t know you needed:</p>

<ul style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;"><strong>IntelliSense</strong> provides real-time code suggestions, function signatures, parameter hints, and inline documentation as you type.</li>
<li style="margin-bottom:0.6em !important;"><strong>Integrated terminal</strong> lets you run Python scripts, install packages with pip, and use Git without leaving the editor.</li>
<li style="margin-bottom:0.6em !important;"><strong>Extensions</strong> let you add Python linting (Pylint, Flake8), auto-formatting (Black, autopep8), Git visualization (GitLens), and thousands more with a single click.</li>
<li style="margin-bottom:0.6em !important;"><strong>Project-aware file explorer</strong> shows your entire project folder tree in a sidebar, making it easy to navigate between files.</li>
<li style="margin-bottom:0.6em !important;"><strong>Professional debugging</strong> with breakpoints, conditional breakpoints, variable inspection, call stacks, and a debug console.</li>
<li style="margin-bottom:0.6em !important;"><strong>Built-in Git support</strong> for version control, viewing diffs, staging changes, and committing code directly from the sidebar.</li>
<li style="margin-bottom:0.6em !important;"><strong>Industry standard</strong> &mdash; learning VS Code now means you already know the tool used at most tech companies, bootcamps, and universities.</li>
</ul>

<!-- Concept callout: Bottom Line -->
<div style="display:flex;border:1px solid #7B2D8E;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#7B2D8E;"></div>
<div style="background:#F3E8F9;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#7B2D8E;">&#x1F4A1; Bottom Line</strong></p>
<p style="margin:0 !important;">Thonny is training wheels. VS Code is the bicycle. Both serve a purpose, but you will go much further and much faster once you make the switch. Everything you learn in VS Code on your Raspberry Pi transfers directly to any other computer or operating system.</p>
</div>
</div>

<!-- ── Prerequisites ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Prerequisites</h2>

<p style="margin-bottom:1.2em !important;">Before you begin, make sure you have the following:</p>

<ul style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;"><strong>Raspberry Pi 4</strong> (4 GB or more recommended) <strong>or Raspberry Pi 5</strong></li>
<li style="margin-bottom:0.6em !important;"><strong>Raspberry Pi OS</strong> installed and working</li>
<li style="margin-bottom:0.6em !important;"><strong>An active internet connection</strong></li>
<li style="margin-bottom:0.6em !important;"><strong>A keyboard, mouse, and monitor</strong> connected to the Pi</li>
</ul>

<!-- Note callout -->
<div style="display:flex;border:1px solid #E65100;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#E65100;"></div>
<div style="background:#FFF3E0;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#E65100;">&#x26A0;&#xFE0F; Note</strong></p>
<p style="margin:0 !important;">VS Code is a full desktop application, and it runs best on a Raspberry Pi 4 or 5 with at least 4 GB of RAM. Older models or 1 GB/2 GB boards may struggle with performance.</p>
</div>
</div>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 1 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 1: Update the Operating System</h2>

<p style="margin-bottom:1.2em !important;">Before installing any new software, you should always update your operating system first. Updates ensure you have the latest security patches, bug fixes, and package information. If you skip this step, you might install an outdated version of a program, or the installation might fail entirely because your system does not know where to find the latest packages.</p>

<p style="margin-bottom:1.2em !important;">Open a Terminal window (you can find it in the taskbar at the top of the screen or in the Accessories menu) and type the following commands one at a time, pressing Enter after each one:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">sudo apt update
sudo apt full-upgrade -y
sudo reboot</pre>

<!-- Concept callout: command explanation -->
<div style="display:flex;border:1px solid #7B2D8E;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#7B2D8E;"></div>
<div style="background:#F3E8F9;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#7B2D8E;">&#x1F4D6; What Do These Commands Mean?</strong></p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>sudo</code></strong> stands for &#8220;Superuser Do.&#8221; It gives you temporary administrator (root) privileges to make system-level changes. Without <code>sudo</code>, the system would block you from installing or updating software because those actions affect all users on the machine.</p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>apt</code></strong> stands for &#8220;Advanced Package Tool.&#8221; It is the package manager for Debian-based Linux systems like Raspberry Pi OS. Think of it as an app store you control from the command line. It knows how to download, install, update, and remove software packages.</p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>apt update</code></strong> tells apt to refresh its list of available software and versions from the internet. It does not install anything &mdash; it just checks what is available.</p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>apt full-upgrade -y</code></strong> downloads and installs all available updates for every package on your system. The <code>-y</code> flag means &#8220;yes to all prompts,&#8221; so you do not have to confirm each update manually.</p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>reboot</code></strong> restarts the Raspberry Pi so that any kernel or system-level updates take effect.</p>
</div>
</div>

<p style="margin-bottom:1.2em !important;">Wait for the Raspberry Pi to restart and log back in before continuing.</p>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 2 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 2: Verify Your Raspberry Pi Model</h2>

<p style="margin-bottom:1.2em !important;">This is an optional but helpful step. You can check exactly which Raspberry Pi model you are using by running:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">cat /proc/device-tree/model</pre>

<p style="margin-bottom:1.2em !important;">You should see output similar to this:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">Raspberry Pi 5 Model B Rev 1.0</pre>

<!-- Concept callout -->
<div style="display:flex;border:1px solid #7B2D8E;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#7B2D8E;"></div>
<div style="background:#F3E8F9;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#7B2D8E;">&#x1F4D6; What Does This Command Mean?</strong></p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>cat</code></strong> is short for &#8220;concatenate.&#8221; It is a command that reads a file and prints its contents to the screen. In this case, the file <code>/proc/device-tree/model</code> is a special system file that stores your Pi&#8217;s hardware identity. You are not opening a normal document &mdash; you are asking Linux to tell you what hardware it is running on.</p>
</div>
</div>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 3 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 3: Install Visual Studio Code</h2>

<p style="margin-bottom:1.2em !important;">Now that your system is up to date, you can install VS Code. Raspberry Pi OS includes VS Code in its official software repositories, so the installation is a single command:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">sudo apt install code -y</pre>

<!-- Concept callout -->
<div style="display:flex;border:1px solid #7B2D8E;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#7B2D8E;"></div>
<div style="background:#F3E8F9;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#7B2D8E;">&#x1F4D6; What Does This Command Mean?</strong></p>
<p style="margin:0.8em 0 0 0 !important;">You already know <code>sudo</code> (run as administrator) and <code>apt</code> (the package manager). The word <strong><code>install</code></strong> tells apt you want to add new software. The word <strong><code>code</code></strong> is the package name for Visual Studio Code in the Raspberry Pi OS repository. Finally, the <code>-y</code> flag automatically answers &#8220;yes&#8221; to any confirmation prompts so the installation proceeds without interruption.</p>
</div>
</div>

<p style="margin-bottom:1.2em !important;">The installation will take a minute or two depending on your internet speed. When it finishes, VS Code is ready to use.</p>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 4 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 4: Launch Visual Studio Code</h2>

<p style="margin-bottom:1.2em !important;">You can start VS Code in two ways:</p>

<h3 style="color:#555;margin-top:1.5em !important;margin-bottom:0.6em !important;">Option A: From the Terminal</h3>

<p style="margin-bottom:1.2em !important;">Type the following command and press Enter:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">code</pre>

<h3 style="color:#555;margin-top:1.5em !important;margin-bottom:0.6em !important;">Option B: From the Desktop Menu</h3>

<p style="margin-bottom:1.2em !important;">Click the Raspberry Pi menu icon in the top-left corner of your screen, navigate to <strong>Programming</strong>, and click <strong>Visual Studio Code</strong>.</p>

<p style="margin-bottom:1.2em !important;">Either method opens the same application. When VS Code launches for the first time, you will see a Welcome tab with helpful links and tips. Feel free to explore it or close it.</p>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 5 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 5: Install the Python Extension</h2>

<p style="margin-bottom:1.2em !important;">Out of the box, VS Code is a general-purpose editor. To unlock its full Python capabilities, you need to install the official Python extension. This is what transforms VS Code from a plain text editor into a Python powerhouse.</p>

<ol style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;">Open Visual Studio Code.</li>
<li style="margin-bottom:0.6em !important;">Click the <strong>Extensions</strong> icon on the left sidebar. It looks like four small squares with one square detached.</li>
<li style="margin-bottom:0.6em !important;">In the search bar at the top, type <strong>Python</strong>.</li>
<li style="margin-bottom:0.6em !important;">Find the extension called <strong>Python</strong> published by <strong>Microsoft</strong> (it will be the first result with millions of installs). Click <strong>Install</strong>.</li>
</ol>

<p style="margin-bottom:1.2em !important;">Once installed, this extension provides:</p>

<ul style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;"><strong>Syntax highlighting</strong> &mdash; Python keywords, strings, and functions are displayed in different colors so your code is easier to read.</li>
<li style="margin-bottom:0.6em !important;"><strong>Code completion (IntelliSense)</strong> &mdash; as you type, VS Code suggests variable names, functions, and methods with documentation popups.</li>
<li style="margin-bottom:0.6em !important;"><strong>Debugging tools</strong> &mdash; set breakpoints, step through code line by line, and inspect variables in real time.</li>
<li style="margin-bottom:0.6em !important;"><strong>Virtual environment support</strong> &mdash; VS Code detects and activates Python virtual environments automatically.</li>
<li style="margin-bottom:0.6em !important;"><strong>Code navigation</strong> &mdash; jump to function definitions, find all references, and rename variables across your entire project.</li>
</ul>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 6 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 6: Verify Python Is Installed</h2>

<p style="margin-bottom:1.2em !important;">Raspberry Pi OS comes with Python pre-installed, but it is good practice to verify the version. Open a Terminal and run:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">python3 --version</pre>

<p style="margin-bottom:1.2em !important;">You should see output like this:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">Python 3.11.x</pre>

<p style="margin-bottom:1.2em !important;">The exact version number may vary depending on your Raspberry Pi OS version. As long as you see Python 3.x, you are good to go.</p>

<!-- Tip callout -->
<div style="display:flex;border:1px solid #00796B;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#00796B;"></div>
<div style="background:#E0F2F1;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#00796B;">&#x1F4A1; Tip</strong></p>
<p style="margin:0 !important;">On Raspberry Pi OS, always use the command <code>python3</code>, not <code>python</code>. Some Linux systems still associate the plain <code>python</code> command with the older Python 2, which is no longer maintained.</p>
</div>
</div>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 7 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 7: Create a Test Project</h2>

<p style="margin-bottom:1.2em !important;">Let&#8217;s create a simple project folder and a Python file to make sure everything is working. In your Terminal, run the following commands:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">mkdir ~/python-test
cd ~/python-test</pre>

<!-- Concept callout -->
<div style="display:flex;border:1px solid #7B2D8E;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#7B2D8E;"></div>
<div style="background:#F3E8F9;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#7B2D8E;">&#x1F4D6; What Do These Commands Mean?</strong></p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>mkdir</code></strong> stands for &#8220;make directory.&#8221; It creates a new folder. The <code>~</code> symbol (called a tilde) is a shortcut that means &#8220;my home folder.&#8221; So <code>mkdir ~/python-test</code> creates a folder called <code>python-test</code> inside your home directory.</p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>cd</code></strong> stands for &#8220;change directory.&#8221; It moves you into the folder you just created. After running <code>cd</code>, any files you create will be saved inside that folder.</p>
</div>
</div>

<p style="margin-bottom:1.2em !important;">Now create a Python file using the nano text editor:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">nano hello.py</pre>

<p style="margin-bottom:1.2em !important;">This opens a simple text editor inside the Terminal. Type the following line of Python code:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">print("Hello from Raspberry Pi!")</pre>

<p style="margin-bottom:1.2em !important;">Save and close the file:</p>

<ol style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;">Press <strong>Ctrl + O</strong> (that is the letter O, not zero) to save.</li>
<li style="margin-bottom:0.6em !important;">Press <strong>Enter</strong> to confirm the filename.</li>
<li style="margin-bottom:0.6em !important;">Press <strong>Ctrl + X</strong> to exit nano.</li>
</ol>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 8 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 8: Open the Project in VS Code</h2>

<p style="margin-bottom:1.2em !important;">Now open your project folder in VS Code. From your Terminal, run:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">code ~/python-test</pre>

<p style="margin-bottom:1.2em !important;">VS Code will open with your <code>python-test</code> folder loaded in the sidebar. You should see your <code>hello.py</code> file listed. Click on it to open it in the editor.</p>

<!-- Tip callout -->
<div style="display:flex;border:1px solid #00796B;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#00796B;"></div>
<div style="background:#E0F2F1;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#00796B;">&#x1F4A1; Tip</strong></p>
<p style="margin:0 !important;">Always open a <em>folder</em> in VS Code rather than individual files. When VS Code has a folder open, it can detect virtual environments, find related files, provide better IntelliSense, and use project-level settings.</p>
</div>
</div>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 9 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 9: Select the Python Interpreter</h2>

<p style="margin-bottom:1.2em !important;">VS Code needs to know which Python installation to use. This is called selecting the <strong>interpreter</strong>.</p>

<ol style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;">Press <strong>Ctrl + Shift + P</strong> to open the Command Palette. This is a search bar that lets you find any VS Code command.</li>
<li style="margin-bottom:0.6em !important;">Type <strong>Python: Select Interpreter</strong> and click the matching option.</li>
<li style="margin-bottom:0.6em !important;">Select <code>/usr/bin/python3</code> from the list. If you have a virtual environment set up (covered later in this guide), you can choose that instead.</li>
</ol>

<p style="margin-bottom:1.2em !important;">Once selected, VS Code will display the interpreter in the bottom status bar so you always know which Python version your project is using.</p>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Step 10 ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Step 10: Run the Program</h2>

<h3 style="color:#555;margin-top:1.5em !important;margin-bottom:0.6em !important;">Option A: Using VS Code</h3>

<p style="margin-bottom:1.2em !important;">With <code>hello.py</code> open in the editor, click the <strong>Run</strong> button (the &#x25B6; play icon) in the upper-right corner of the editor. VS Code will open its built-in terminal at the bottom of the screen and run your script.</p>

<h3 style="color:#555;margin-top:1.5em !important;margin-bottom:0.6em !important;">Option B: Using the Terminal</h3>

<p style="margin-bottom:1.2em !important;">If you prefer, you can run the script directly from any Terminal window:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">python3 hello.py</pre>

<p style="margin-bottom:1.2em !important;">Either way, you should see the following output:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">Hello from Raspberry Pi!</pre>

<!-- Checkpoint callout -->
<div style="display:flex;border:1px solid #2E7D32;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#2E7D32;"></div>
<div style="background:#E8F5E9;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#2E7D32;">&#x2705; Checkpoint</strong></p>
<p style="margin:0 !important;">If you see the message above, congratulations! You have successfully installed VS Code, configured it for Python, and run your first program. The remaining sections are optional but highly recommended.</p>
</div>
</div>

<hr style="border:none;border-top:2px solid #2E75B6;margin:2.5em 0 !important;">

<!-- ── Optional: Virtual Environment ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Optional: Create a Virtual Environment</h2>

<p style="margin-bottom:1.2em !important;">A virtual environment is an isolated copy of Python that lives inside your project folder. It lets you install packages for one project without affecting any other project or the system-wide Python installation. This is considered a best practice in Python development.</p>

<p style="margin-bottom:1.2em !important;">First, install the virtual environment package:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">sudo apt install python3-venv -y</pre>

<p style="margin-bottom:1.2em !important;">Then create and activate a virtual environment inside your project folder:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">cd ~/python-test
python3 -m venv .venv
source .venv/bin/activate</pre>

<!-- Concept callout -->
<div style="display:flex;border:1px solid #7B2D8E;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#7B2D8E;"></div>
<div style="background:#F3E8F9;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#7B2D8E;">&#x1F4D6; What Do These Commands Mean?</strong></p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>python3 -m venv .venv</code></strong> tells Python to run its built-in <code>venv</code> module and create a virtual environment in a hidden folder called <code>.venv</code> inside your project directory. The dot at the beginning of <code>.venv</code> makes it a hidden folder in Linux (it will not clutter your file listing).</p>
<p style="margin:0.8em 0 0 0 !important;"><strong><code>source .venv/bin/activate</code></strong> runs the activation script. After activation, your terminal prompt will change to show <code>(.venv)</code> at the beginning, which tells you the virtual environment is active. Any <code>pip install</code> commands you run now will install packages only inside this environment.</p>
</div>
</div>

<p style="margin-bottom:1.2em !important;">You should see your terminal prompt change to something like:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">(.venv) pi@raspberrypi:~/python-test $</pre>

<p style="margin-bottom:1.2em !important;">Now you can install packages safely. For example:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">pip install requests</pre>

<p style="margin-bottom:1.2em !important;">VS Code will usually detect the virtual environment automatically and ask if you want to use it as your interpreter. Click <strong>Yes</strong> when prompted.</p>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Optional: Git ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Optional: Install Git</h2>

<p style="margin-bottom:1.2em !important;">Git is a version control system that tracks changes to your code over time. It lets you save snapshots of your project, undo mistakes, collaborate with others, and share your code on platforms like GitHub. If you are learning to code, learning Git early is one of the best investments you can make.</p>

<p style="margin-bottom:1.2em !important;">Install Git:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">sudo apt install git -y</pre>

<p style="margin-bottom:1.2em !important;">Configure your identity (Git uses this to label your commits):</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">git config --global user.name "Your Name"
git config --global user.email "you@example.com"</pre>

<p style="margin-bottom:1.2em !important;">Verify the installation:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">git --version</pre>

<p style="margin-bottom:1.2em !important;">You should see output like:</p>

<pre style="background:#F0F0F0;border:1px solid #CCC;border-radius:4px;padding:14px 18px !important;font-family:'Consolas','Courier New',monospace;font-size:0.95em;line-height:1.6;overflow-x:auto;margin-bottom:1.2em !important;">git version 2.39.x</pre>

<p style="margin-bottom:1.2em !important;">Once Git is installed, VS Code&#8217;s built-in <strong>Source Control</strong> panel (the branch icon on the left sidebar) will automatically detect Git repositories and let you stage, commit, and push changes without leaving the editor.</p>

<hr style="border:none;border-top:1px solid #ddd;margin:2.5em 0 !important;">

<!-- ── Recommended Extensions ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Recommended VS Code Extensions</h2>

<p style="margin-bottom:1.2em !important;">Now that VS Code is set up, here are some extensions worth installing from the Extensions marketplace to further improve your workflow:</p>

<ul style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;"><strong>Python</strong> (Microsoft) &mdash; the core extension you already installed. Provides IntelliSense, debugging, and environment management.</li>
<li style="margin-bottom:0.6em !important;"><strong>Pylance</strong> (Microsoft) &mdash; a faster, more powerful Python language server that improves type checking, auto-imports, and code navigation. It is often installed automatically alongside the Python extension.</li>
<li style="margin-bottom:0.6em !important;"><strong>GitHub Pull Requests and Issues</strong> (GitHub) &mdash; if you use GitHub, this extension lets you create pull requests, review code, and manage issues directly inside VS Code.</li>
<li style="margin-bottom:0.6em !important;"><strong>GitLens</strong> (GitKraken) &mdash; adds powerful Git annotations, blame info, and history visualization so you can see who changed what and when.</li>
<li style="margin-bottom:0.6em !important;"><strong>Docker</strong> (Microsoft) &mdash; optional. If you work with containers, this extension makes managing Docker images and containers much easier.</li>
</ul>

<hr style="border:none;border-top:2px solid #2E75B6;margin:2.5em 0 !important;">

<!-- ── Summary ── -->

<h2 style="color:#2E75B6;margin-top:2em !important;margin-bottom:0.8em !important;">Summary</h2>

<p style="margin-bottom:1.2em !important;">After completing this guide, your Raspberry Pi now has:</p>

<ul style="margin-top:0.8em !important;margin-bottom:1.2em !important;">
<li style="margin-bottom:0.6em !important;">Visual Studio Code installed and configured</li>
<li style="margin-bottom:0.6em !important;">The Python extension providing IntelliSense, debugging, and code navigation</li>
<li style="margin-bottom:0.6em !important;">A verified Python installation ready for development</li>
<li style="margin-bottom:0.6em !important;">Optional virtual environment support for isolated project dependencies</li>
<li style="margin-bottom:0.6em !important;">Optional Git integration for version control</li>
</ul>

<p style="margin-bottom:1.2em !important;">This setup closely mirrors the environment used by professional Python developers working on Linux servers, cloud systems, and production applications. Everything you learn here transfers directly to any computer running VS Code, regardless of operating system.</p>

<!-- Tip callout: What's Next -->
<div style="display:flex;border:1px solid #00796B;border-radius:4px;overflow:hidden;margin:1.5em 0 !important;">
<div style="width:6px;min-width:6px;background:#00796B;"></div>
<div style="background:#E0F2F1;padding:16px 20px !important;flex:1;">
<p style="margin:0 0 0.5em 0 !important;"><strong style="color:#00796B;">&#x1F680; What&#8217;s Next?</strong></p>
<p style="margin:0 !important;">Start building! Open VS Code, create a new Python file, and write something. Experiment with the IntelliSense suggestions, try setting a breakpoint, and explore the integrated terminal. The best way to learn a tool is to use it.</p>
</div>
</div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Understanding Python’s Built-In Debugger (pdb): A Guide for New Developers</title>
		<link>https://sekol.ninja/understanding-pythons-built-in-debugger-pdb-a-guide-for-new-developers/</link>
		
		<dc:creator><![CDATA[Michael Sekol]]></dc:creator>
		<pubDate>Mon, 04 Nov 2024 04:37:27 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[new developer]]></category>
		<category><![CDATA[walkthrough]]></category>
		<guid isPermaLink="false">https://sekol.ninja/?p=1997</guid>

					<description><![CDATA[Debugging is an essential part of writing code. It helps you find and fix errors, verify your program’s logic, and ultimately improve [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Debugging is an essential part of writing code. It helps you find and fix errors, verify your program’s logic, and ultimately improve your code’s quality and reliability. One of Python’s most powerful and accessible tools for debugging is the built-in <code>pdb</code> module, a debugger that lets you interact with your code as it runs, check variable values, inspect program flow, and even change variable states on the fly.</p>



<p class="wp-block-paragraph">In this guide, we’ll take an in-depth look at <code>pdb</code>, covering why it’s useful, how to use it effectively, and exploring the commands that make debugging with <code>pdb</code> so powerful. This article will provide you with step-by-step examples so that by the end, you’ll feel comfortable using <code>pdb</code> to debug your own code.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">What is <code>pdb</code>?</h2>



<p class="wp-block-paragraph"><code>pdb</code> stands for <strong>Python Debugger</strong>. It’s a module that comes with Python and provides a command-line interface to inspect and control the flow of your program as it runs. By setting breakpoints (points at which the program pauses), you can check variable values, examine the code’s state, and ensure that each part of your program behaves as expected.</p>



<h3 class="wp-block-heading">Why Use <code>pdb</code>?</h3>



<ul class="wp-block-list">
<li><strong>Immediate Feedback</strong>: <code>pdb</code> lets you pause your program’s execution at specific points and see exactly what’s happening in real-time.</li>



<li><strong>Interactive Debugging</strong>: You can run commands, check variables, and even change values directly while the program is paused.</li>



<li><strong>Step-by-Step Execution</strong>: You can execute your code one line at a time, making it easier to locate exactly where something is going wrong.</li>
</ul>



<p class="wp-block-paragraph">Using <code>pdb</code> encourages developers to write more efficient and bug-free code by making it easier to identify and understand issues within the code.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Setting Up <code>pdb</code> in Your Code</h2>



<p class="wp-block-paragraph">To use <code>pdb</code>, import it into your code:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import pdb</pre>



<p class="wp-block-paragraph">Once imported, you can set breakpoints with:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">pdb.set_trace()</pre>



<p class="wp-block-paragraph">When your code reaches <code>pdb.set_trace()</code>, it will pause, and you’ll enter an interactive <code>pdb</code> console. From there, you can issue commands to check variable values, step through code, and more.</p>



<h3 class="wp-block-heading">Example: Basic <code>pdb</code> Setup</h3>



<p class="wp-block-paragraph">Here’s a simple example of using <code>pdb</code> to pause a program:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import pdb

def add_numbers(a, b):
    pdb.set_trace()  # Pause execution here
    result = a + b
    return result

print(add_numbers(3, 5))</pre>



<p class="wp-block-paragraph">When this code runs, execution will pause at <code>pdb.set_trace()</code>. You’ll see the <code>pdb</code> console, where you can enter commands to explore the current state of your code.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Basic <code>pdb</code> Commands</h2>



<p class="wp-block-paragraph">Let’s dive into the most commonly used commands in <code>pdb</code>:</p>



<h3 class="wp-block-heading">1. <strong>Inspecting Variables</strong></h3>



<p class="wp-block-paragraph">To check the value of a variable, simply type the variable name in the <code>pdb</code> console:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">> print(a)
3
> print(b)
5</pre>



<h3 class="wp-block-heading">2. <strong>Navigating Through Code</strong></h3>



<ul class="wp-block-list">
<li><strong><code>n</code> (next)</strong>: Executes the current line and moves to the next line in the function.</li>



<li><strong><code>s</code> (step)</strong>: Steps into a function if there’s one on the current line.</li>



<li><strong><code>c</code> (continue)</strong>: Resumes execution until the next breakpoint or until the program completes.</li>



<li><strong><code>q</code> (quit)</strong>: Exits the debugger and stops the program.</li>
</ul>



<h3 class="wp-block-heading">3. <strong>Setting Breakpoints</strong></h3>



<p class="wp-block-paragraph">You can set breakpoints dynamically, even within the <code>pdb</code> console:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">> b 10  # Set a breakpoint at line 10</pre>



<p class="wp-block-paragraph">To remove breakpoints:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">> cl  # Clears all breakpoints</pre>



<h3 class="wp-block-heading">Example Walkthrough Using <code>pdb</code> Commands</h3>



<p class="wp-block-paragraph">Let’s say we’re debugging the following function:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import pdb

def greet(name):
    if not name:
        name = "world"
    pdb.set_trace()  # Start debugging here
    greeting = "Hello, " + name + "!"
    print(greeting)

greet("")</pre>



<ul class="wp-block-list">
<li><strong>Step 1</strong>: The code pauses at <code>pdb.set_trace()</code>. Type <code>name</code> to inspect its current value (<code>""</code>).</li>



<li><strong>Step 2</strong>: Type <code>n</code> to move to the next line (<code>name = "world"</code>).</li>



<li><strong>Step 3</strong>: Enter <code>greeting</code> to check if it holds the expected value, then <code>c</code> to continue the program.</li>
</ul>



<p class="wp-block-paragraph">This example shows how <code>pdb</code> lets you inspect and control your program line by line, helping you pinpoint exactly where issues arise.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Advanced <code>pdb</code> Commands</h2>



<p class="wp-block-paragraph">Once you’re comfortable with the basics, you can take your debugging to the next level by using advanced commands:</p>



<h3 class="wp-block-heading">1. <strong>Listing Code Around Your Position</strong></h3>



<ul class="wp-block-list">
<li><strong><code>l</code> (list)</strong>: Displays a few lines of code around your current position, providing context.</li>



<li><strong><code>w</code> (where)</strong>: Shows the full call stack, so you can see which functions were called to reach the current line.</li>
</ul>



<h3 class="wp-block-heading">2. <strong>Setting Conditional Breakpoints</strong></h3>



<p class="wp-block-paragraph">Sometimes, you only want the program to pause if a certain condition is met. You can set conditional breakpoints like this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">> b 15, a == 5  # Sets a breakpoint at line 15 only if a equals 5</pre>



<h3 class="wp-block-heading">3. <strong>Changing Variables on the Fly</strong></h3>



<p class="wp-block-paragraph">In <code>pdb</code>, you can assign new values to variables during execution, allowing you to see how different inputs affect your code.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">> a = 10
> print(a)
10</pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Putting It All Together: <code>pdb</code> in Practice</h2>



<p class="wp-block-paragraph">Here’s a more complex example that combines several <code>pdb</code> commands.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import pdb

def divide_numbers(a, b):
    pdb.set_trace()  # Pause at the beginning of the function
    if b == 0:
        return "Cannot divide by zero!"
    else:
        return a / b

result = divide_numbers(10, 0)
print(result)</pre>



<h3 class="wp-block-heading">Step-by-Step Debugging Walkthrough</h3>



<ol class="wp-block-list">
<li><strong>Inspect Variables</strong>: Use <code>pdb</code> to check <code>a</code> and <code>b</code>.</li>



<li><strong>Check Conditions</strong>: Step through the <code>if</code> condition with <code>n</code> to confirm the logic.</li>



<li><strong>Test New Inputs</strong>: Change <code>b</code> to a non-zero value to see how it affects <code>result</code>.</li>



<li><strong>Quit Debugging</strong>: Once you understand the error, use <code>q</code> to exit <code>pdb</code>.</li>
</ol>



<p class="wp-block-paragraph">This example illustrates how <code>pdb</code> helps you test assumptions and understand the flow of control in your program.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Using <code>pdb</code> to Write Better Code</h2>



<p class="wp-block-paragraph">Debugging with <code>pdb</code> is more than just finding errors—it’s about understanding how your code behaves, ensuring your logic is sound, and improving code quality. Here are a few tips for using <code>pdb</code> to write better code:</p>



<ol class="wp-block-list">
<li><strong>Set Breakpoints Strategically</strong>: Place breakpoints at key points where logic changes (e.g., loops, conditionals).</li>



<li><strong>Inspect Variables Regularly</strong>: Check variable values often to confirm that they hold expected values.</li>



<li><strong>Use Conditional Breakpoints</strong>: Focus on specific scenarios by setting conditional breakpoints to catch edge cases.</li>



<li><strong>Test Edge Cases</strong>: Use <code>pdb</code> to simulate different inputs, especially edge cases (e.g., dividing by zero).</li>
</ol>



<p class="wp-block-paragraph">By using <code>pdb</code>, you can develop a deeper understanding of your code, leading to cleaner, more reliable, and well-optimized programs.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Example: Using <code>pdb</code> to Debug a Program with Inheritance</h2>



<p class="wp-block-paragraph">Let’s say you’re working with classes and inheritance. Here’s how <code>pdb</code> can help clarify object interactions.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import pdb

class Animal:
    def __init__(self, name):
        self.name = name

    def speak(self):
        return "Some sound"

class Dog(Animal):
    def speak(self):
        return "Woof!"

class Cat(Animal):
    def speak(self):
        return "Meow"

def animal_sound(animal):
    pdb.set_trace()  # Pause to inspect the animal object
    print(animal.speak())

dog = Dog("Buddy")
cat = Cat("Whiskers")

animal_sound(dog)
animal_sound(cat)</pre>



<h3 class="wp-block-heading">Walkthrough</h3>



<ul class="wp-block-list">
<li><strong>Inspect the <code>animal</code> Object</strong>: Use <code>p animal</code> to check whether <code>animal</code> is a <code>Dog</code> or <code>Cat</code> instance.</li>



<li><strong>Step Into Methods</strong>: Use <code>s</code> on <code>animal.speak()</code> to step into the <code>speak</code> method and observe polymorphism in action.</li>



<li><strong>Check Attribute Values</strong>: Type <code>animal.name</code> to verify that each animal object has the correct name.</li>
</ul>



<p class="wp-block-paragraph">Using <code>pdb</code> here lets you verify inheritance and polymorphism in a structured way.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Final Thoughts: Why <code>pdb</code> is Essential for New Developers</h2>



<p class="wp-block-paragraph">Learning to use <code>pdb</code> effectively is a major step in becoming a proficient programmer. Here’s why every developer should become familiar with it:</p>



<ol class="wp-block-list">
<li><strong>Promotes Interactive Learning</strong>: <code>pdb</code> allows for hands-on exploration, helping developers grasp code behavior and flow in real time.</li>



<li><strong>Teaches Systematic Debugging</strong>: By stepping through code, new developers learn to follow a logical process, identifying root causes more efficiently.</li>



<li><strong>Encourages Better Code Quality</strong>: Debugging regularly with <code>pdb</code> reinforces habits that lead to more thorough testing, cleaner code, and fewer errors in production</li>
</ol>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Kickstart Your Python Journey: Setting Up a Virtual Environment in Visual Studio Code</title>
		<link>https://sekol.ninja/kickstart-your-python-journey-setting-up-a-virtual-environment-in-visual-studio-code/</link>
		
		<dc:creator><![CDATA[Michael Sekol]]></dc:creator>
		<pubDate>Fri, 01 Nov 2024 03:37:51 +0000</pubDate>
				<category><![CDATA[Intro to Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<category><![CDATA[venv]]></category>
		<category><![CDATA[Virtual Environment]]></category>
		<guid isPermaLink="false">https://sekol.ninja/?p=1988</guid>

					<description><![CDATA[Introduction: The Power of Virtual Environments In the ever-evolving landscape of software development, maintaining clean and organized code is paramount. As a [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction: The Power of Virtual Environments</h2>



<p class="wp-block-paragraph">In the ever-evolving landscape of software development, maintaining clean and organized code is paramount. As a new developer, you’ll often encounter various projects requiring different dependencies. This is where <strong>Python virtual environments</strong> come into play. A virtual environment is an isolated workspace that allows you to manage project-specific dependencies without interfering with other projects. In this guide, we’ll explore why and when to use virtual environments, how to set them up in Visual Studio Code (VS Code) on both Mac and PC, and share essential commands, common pitfalls, and their solutions.</p>



<h2 class="wp-block-heading">Why Use a Virtual Environment?</h2>



<h3 class="wp-block-heading">1. Dependency Management</h3>



<p class="wp-block-paragraph">When working on multiple projects, each may rely on different versions of libraries or packages. A virtual environment allows you to manage these dependencies separately, preventing version conflicts.</p>



<h3 class="wp-block-heading">2. Clean Workspace</h3>



<p class="wp-block-paragraph">By isolating dependencies, you keep your global Python installation clean. This means fewer complications and a more straightforward path to debugging.</p>



<h3 class="wp-block-heading">3. Simplified Collaboration</h3>



<p class="wp-block-paragraph">Using virtual environments makes it easier to share your project with others. You can provide a requirements file that lists all dependencies, allowing collaborators to set up their environments easily.</p>



<h2 class="wp-block-heading">When to Use a Virtual Environment</h2>



<ul class="wp-block-list">
<li><strong>Starting a New Project</strong>: Always create a new virtual environment when beginning a new project.</li>



<li><strong>Experimenting with Libraries</strong>: If you want to test new libraries without affecting your current setup, a virtual environment is ideal.</li>



<li><strong>Collaborative Projects</strong>: When working with others, using a virtual environment ensures everyone is on the same page regarding dependencies.</li>
</ul>



<h2 class="wp-block-heading">Setting Up a Python Virtual Environment in Visual Studio Code</h2>



<h3 class="wp-block-heading">Prerequisites</h3>



<p class="wp-block-paragraph">Before diving into the setup, ensure you have the following:</p>



<ul class="wp-block-list">
<li><strong>Python Installed</strong>: Download and install Python from the <a href="https://www.python.org/downloads/">official website</a>.</li>



<li><strong>Visual Studio Code Installed</strong>: Get the latest version from the <a href="https://code.visualstudio.com/">official website</a>.</li>



<li><strong>Python Extension for VS Code</strong>: Install the Python extension from the VS Code Marketplace to enhance your development experience.</li>
</ul>



<h3 class="wp-block-heading">Setting Up on macOS</h3>



<h4 class="wp-block-heading">Step 1: Open Terminal</h4>



<ol class="wp-block-list">
<li>Open the <strong>Terminal</strong> application from your Applications folder or by searching in Spotlight.</li>
</ol>



<h4 class="wp-block-heading">Step 2: Navigate to Your Project Directory</h4>



<p class="wp-block-paragraph">Use the <code>cd</code> command to change to your project directory.</p>



<pre class="wp-block-preformatted"><code>cd /path/to/your/project</code></pre>



<h4 class="wp-block-heading">Step 3: Create a Virtual Environment</h4>



<p class="wp-block-paragraph">Run the following command to create a virtual environment named <code>venv</code>:</p>



<pre class="wp-block-preformatted"><code>python3 -m venv venv</code></pre>



<h4 class="wp-block-heading">Step 4: Activate the Virtual Environment</h4>



<p class="wp-block-paragraph">To activate the virtual environment, run:</p>



<pre class="wp-block-preformatted"><code>source venv/bin/activate</code></pre>



<p class="wp-block-paragraph">You should see <code>(venv)</code> at the beginning of your terminal prompt, indicating that the virtual environment is active.</p>



<h4 class="wp-block-heading">Step 5: Open Visual Studio Code</h4>



<ol class="wp-block-list">
<li>Type <code>code .</code> in the terminal to open VS Code in the current directory.</li>
</ol>



<h3 class="wp-block-heading">Setting Up on Windows</h3>



<h4 class="wp-block-heading">Step 1: Open Command Prompt or PowerShell</h4>



<p class="wp-block-paragraph">You can search for <code>cmd</code> or <code>PowerShell</code> in the Start menu.</p>



<h4 class="wp-block-heading">Step 2: Navigate to Your Project Directory</h4>



<p class="wp-block-paragraph">Use the <code>cd</code> command to change to your project directory.</p>



<pre class="wp-block-preformatted"><code>cd C:\path\to\your\project</code></pre>



<h4 class="wp-block-heading">Step 3: Create a Virtual Environment</h4>



<p class="wp-block-paragraph">Run the following command to create a virtual environment named <code>venv</code>:</p>



<pre class="wp-block-preformatted"><code>python -m venv venv</code></pre>



<h4 class="wp-block-heading">Step 4: Activate the Virtual Environment</h4>



<p class="wp-block-paragraph">To activate the virtual environment, use:</p>



<pre class="wp-block-preformatted"><code>.\venv\Scripts\activate<br></code></pre>



<p class="wp-block-paragraph">You should see <code>(venv)</code> at the beginning of your command prompt, indicating that the virtual environment is active.</p>



<h4 class="wp-block-heading">Step 5: Open Visual Studio Code</h4>



<ol class="wp-block-list">
<li>Type <code>code .</code> in the command prompt to open VS Code in the current directory.</li>
</ol>



<h2 class="wp-block-heading">Essential Commands for Managing Your Virtual Environment</h2>



<ul class="wp-block-list">
<li><strong>Activate Virtual Environment</strong>:
<ul class="wp-block-list">
<li><strong>macOS</strong>: <code>source venv/bin/activate</code></li>



<li><strong>Windows</strong>: <code>.\venv\Scripts\activate</code></li>
</ul>
</li>



<li><strong>Deactivate Virtual Environment</strong>:
<ul class="wp-block-list">
<li>Use the command <code>deactivate</code> in the terminal.</li>
</ul>
</li>



<li><strong>Install Packages</strong>: <code>pip install package_name</code></li>



<li><strong>List Installed Packages</strong>: <code>pip list</code></li>



<li><strong>Freeze Dependencies</strong>: To create a <code>requirements.txt</code> file containing all installed packages, use: <code>pip freeze > requirements.txt</code></li>



<li><strong>Install from <code>requirements.txt</code></strong>: To install all packages listed in a requirements file: <code>pip install -r requirements.txt</code></li>
</ul>



<h2 class="wp-block-heading">Common Pitfalls and Solutions</h2>



<h3 class="wp-block-heading">Pitfall 1: Forgetting to Activate the Virtual Environment</h3>



<p class="wp-block-paragraph"><strong>Solution</strong>: Always ensure that the virtual environment is activated before running your scripts or installing packages. If you forget, simply run the activation command again.</p>



<h3 class="wp-block-heading">Pitfall 2: Using Global Python Instead of the Virtual Environment</h3>



<p class="wp-block-paragraph"><strong>Solution</strong>: Double-check that your terminal is showing the virtual environment&#8217;s name (like <code>(venv)</code>) before executing Python commands or installing packages.</p>



<h3 class="wp-block-heading">Pitfall 3: Dependencies Not Working After Deactivation</h3>



<p class="wp-block-paragraph"><strong>Solution</strong>: Remember that when you deactivate the virtual environment, all dependencies installed are only available while it is active. Reactivate the environment to use those dependencies.</p>



<h3 class="wp-block-heading">Pitfall 4: Confusing Virtual Environments with Different Projects</h3>



<p class="wp-block-paragraph"><strong>Solution</strong>: Use descriptive names for your virtual environments (e.g., <code>venv_webapp</code>, <code>venv_data_analysis</code>) to easily distinguish between them.</p>



<h2 class="wp-block-heading">Conclusion: Empowering Your Coding Journey</h2>



<p class="wp-block-paragraph">Setting up a Python virtual environment in Visual Studio Code is a vital skill for any aspiring developer. It helps you manage dependencies effectively, keep your projects organized, and simplify collaboration with others. By following the steps outlined in this guide, you’ll be well on your way to creating robust, isolated environments for your projects.</p>



<p class="wp-block-paragraph">So, whether you’re embarking on your coding journey or looking to enhance your development practices, remember: a well-managed environment is key to success!</p>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Understanding Basic Syntax and Structure in Programming</title>
		<link>https://sekol.ninja/understanding-basic-syntax-and-structure-in-programming/</link>
		
		<dc:creator><![CDATA[Michael Sekol]]></dc:creator>
		<pubDate>Wed, 30 Oct 2024 21:32:02 +0000</pubDate>
				<category><![CDATA[Intro to Programming]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://sekol.ninja/?p=1973</guid>

					<description><![CDATA[Welcome to the world of programming! If you&#8217;re just starting, one of the first things you&#8217;ll encounter is the syntax and structure [&#8230;]]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-audio"><audio controls src="https://sekol.ninja/wp-content/uploads/2024/10/Understanding-Syntax.mp3"></audio></figure>



<p class="wp-block-paragraph">Welcome to the world of programming! If you&#8217;re just starting, one of the first things you&#8217;ll encounter is the <strong>syntax and structure</strong> of programming languages. Understanding these concepts is crucial for writing effective and error-free code. In this article, we&#8217;ll explore variables, data types, operators, and control flow statements using popular languages like Python and JavaScript.</p>



<h2 class="wp-block-heading">What is Syntax?</h2>



<p class="wp-block-paragraph"><strong>Syntax</strong> refers to the set of rules that define the combinations of symbols and expressions that are considered to be correctly structured programs in a programming language. Each language has its own syntax, much like how each spoken language has its own grammatical rules.</p>



<h3 class="wp-block-heading">Variables</h3>



<p class="wp-block-paragraph">A <strong>variable</strong> is a symbolic name associated with a value and whose associated value may be changed. Variables allow us to store data and manipulate it throughout our code.</p>



<p class="wp-block-paragraph"><strong>Example in Python:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># Defining a variable
age = 25
name = "Alice"</pre>



<p class="wp-block-paragraph"><strong>Example in JavaScript:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// Defining a variable
let age = 25;
const name = "Alice"; // constant variable, cannot be changed</pre>



<h3 class="wp-block-heading">Data Types</h3>



<p class="wp-block-paragraph">Data types specify the kind of data a variable can hold. Common data types include:</p>



<ul class="wp-block-list">
<li><strong>Integers</strong> (whole numbers)</li>



<li><strong>Floats</strong> (decimal numbers)</li>



<li><strong>Strings</strong> (text)</li>



<li><strong>Booleans</strong> (true/false)</li>
</ul>



<p class="wp-block-paragraph"><strong>Example in Python</strong>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">integer_number = 10           # Integer
float_number = 10.5          # Float
string_value = "Hello, World!" # String
is_active = True              # Boolean</pre>



<p class="wp-block-paragraph"><strong>Example in JavaScript:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">let integerNumber = 10;        // Integer
let floatNumber = 10.5;        // Float
let stringValue = "Hello, World!"; // String
let isActive = true;           // Boolean</pre>



<h3 class="wp-block-heading">Operators</h3>



<p class="wp-block-paragraph">Operators are special symbols that perform operations on variables and values. Common operators include:</p>



<ul class="wp-block-list">
<li><strong>Arithmetic Operators</strong>: +, -, *, / (addition, subtraction, multiplication, division)</li>



<li><strong>Comparison Operators</strong>: ==, !=, &gt;, &lt; (equality, inequality, greater than, less than)</li>



<li><strong>Logical Operators</strong>: and, or, not (logical conjunction, disjunction, negation)</li>
</ul>



<p class="wp-block-paragraph"><strong>Example in Python:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># Arithmetic
sum_value = 10 + 5           # 15

# Comparison
is_equal = (10 == 10)        # True

# Logical
is_valid = (True and False)  # False</pre>



<p class="wp-block-paragraph"><strong>Example in JavaScript:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// Arithmetic
let sumValue = 10 + 5;       // 15

// Comparison
let isEqual = (10 === 10);   // True

// Logical
let isValid = (true &amp;&amp; false); // False</pre>



<h3 class="wp-block-heading">Control Flow Statements</h3>



<p class="wp-block-paragraph">Control flow statements allow us to dictate the order in which code executes. The most common control flow statements are <strong>if-else</strong> statements and loops.</p>



<h4 class="wp-block-heading">If-Else Statements</h4>



<p class="wp-block-paragraph">If-else statements let you execute certain blocks of code based on conditions.</p>



<p class="wp-block-paragraph"><strong>Example in Python:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if age >= 18:
    print("You are an adult.")
else:
    print("You are a minor.")
</pre>



<p class="wp-block-paragraph"><strong>Example in JavaScript:</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if (age >= 18) {
    console.log("You are an adult.");
} else {
    console.log("You are a minor.");
}</pre>



<h4 class="wp-block-heading">Loops</h4>



<p class="wp-block-paragraph">Loops allow you to repeat a block of code multiple times. The most common types of loops are <strong>for</strong> loops and <strong>while</strong> loops.</p>



<p class="wp-block-paragraph"><strong>Example in Python (For Loop):</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">for i in range(5):
    print(i)  # Prints numbers 0 to 4</pre>



<p class="wp-block-paragraph"><strong>Example in JavaScript (While Loop):</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">let i = 0;
while (i &lt; 5) {
    console.log(i);  // Prints numbers 0 to 4
    i++;
}</pre>



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



<p class="wp-block-paragraph">Mastering the basic syntax and structure of programming languages is essential for any aspiring programmer. By understanding variables, data types, operators, and control flow statements, you&#8217;ll build a strong foundation for more advanced programming concepts.</p>



<p class="wp-block-paragraph">So, grab your coding editor, practice writing some of these examples, and start your journey into the exciting world of programming!</p>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		<enclosure url="https://sekol.ninja/wp-content/uploads/2024/10/Understanding-Syntax.mp3" length="3111840" type="audio/mpeg" />

			</item>
		<item>
		<title>Demystifying Classes and Objects in Python: A Beginner&#8217;s Guide</title>
		<link>https://sekol.ninja/demystifying-classes-and-objects-in-python-a-beginners-guide/</link>
		
		<dc:creator><![CDATA[Michael Sekol]]></dc:creator>
		<pubDate>Wed, 30 Oct 2024 17:03:52 +0000</pubDate>
				<category><![CDATA[Intro to Programming]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://sekol.ninja/?p=1962</guid>

					<description><![CDATA[Welcome to the exciting world of Python, where we transform ideas into reality through code! Today, we&#8217;re exploring one of the fundamental [&#8230;]]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-audio"><audio controls src="https://sekol.ninja/wp-content/uploads/2024/10/DeClass.mp3"></audio></figure>



<p class="wp-block-paragraph">Welcome to the exciting world of Python, where we transform ideas into reality through code! Today, we&#8217;re exploring one of the fundamental concepts in programming: <strong>Classes and Objects</strong>. If you’re new to coding or looking to deepen your understanding, you’re in the right place!</p>



<h2 class="wp-block-heading"><strong>Understanding the Basics of Object-Oriented Programming (OOP)</strong></h2>



<p class="wp-block-paragraph">At its core, <strong>Object-Oriented Programming (OOP)</strong> is a way to structure and organize your code. Imagine it like building a house. Just as a house is made up of various components like walls, doors, and windows, an object in programming consists of <strong>data</strong> (attributes) and <strong>operations</strong> (methods).</p>



<h3 class="wp-block-heading"><strong>What are Classes?</strong></h3>



<p class="wp-block-paragraph"><strong>Classes</strong> are blueprints for creating objects. Just as architects design buildings, programmers design classes. A class defines the attributes and methods that its objects will have.</p>



<p class="wp-block-paragraph">For instance, consider a class called Dog. It may have attributes like name, age, and breed, and methods like bark() or fetch(). Here’s how you would define a simple Dog class in Python:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Dog:

    def __init__(self, name, age, breed):

        self.name = name  # Attribute to store the dog's name

        self.age = age    # Attribute to store the dog's age

        self.breed = breed  # Attribute to store the dog's breed

    def bark(self):  # Method for the dog to bark

        return "Woof!"

    def fetch(self, item):  # Method for fetching an item

        return f"{self.name} fetched the {item}!"</pre>



<h3 class="wp-block-heading"><strong>The </strong><strong>__init__</strong><strong> Method and the </strong><strong>self</strong><strong> Parameter</strong></h3>



<p class="wp-block-paragraph">In the Dog class above, the __init__ method is a special method called a <strong>constructor</strong>. Python calls this method when you create a new instance of the class. It initializes the object&#8217;s attributes.</p>



<p class="wp-block-paragraph">The self parameter in method definitions refers to the current instance of the class. It’s how you access variables and methods associated with the current object.</p>



<h3 class="wp-block-heading"><strong>What are Objects?</strong></h3>



<p class="wp-block-paragraph"><strong>Objects</strong> are instances of classes. Continuing with the house analogy, if a class is the blueprint, an object is the actual house built from that blueprint. Each object (or instance) of a class can have different attribute values, but they all share the same methods.</p>



<p class="wp-block-paragraph">Let’s create an object from the Dog class:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># Creating an instance of the Dog class

buddy = Dog("Buddy", 3, "Golden Retriever")

# Accessing attributes

print(buddy.name)  # Output: Buddy

print(buddy.age)   # Output: 3

print(buddy.breed) # Output: Golden Retriever

# Calling methods

print(buddy.bark())              # Output: Woof!

print(buddy.fetch("ball"))       # Output: Buddy fetched the ball!</pre>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="585" src="https://sekol.ninja/wp-content/uploads/2024/10/doggocode-1024x585.webp" alt="" class="wp-image-1965" srcset="https://sekol.ninja/wp-content/uploads/2024/10/doggocode-1024x585.webp 1024w, https://sekol.ninja/wp-content/uploads/2024/10/doggocode-300x171.webp 300w, https://sekol.ninja/wp-content/uploads/2024/10/doggocode-768x439.webp 768w, https://sekol.ninja/wp-content/uploads/2024/10/doggocode-1536x878.webp 1536w, https://sekol.ninja/wp-content/uploads/2024/10/doggocode-1000x571.webp 1000w, https://sekol.ninja/wp-content/uploads/2024/10/doggocode-230x131.webp 230w, https://sekol.ninja/wp-content/uploads/2024/10/doggocode-350x200.webp 350w, https://sekol.ninja/wp-content/uploads/2024/10/doggocode-480x274.webp 480w, https://sekol.ninja/wp-content/uploads/2024/10/doggocode.webp 1792w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading"><strong>The Power of OOP</strong></h3>



<p class="wp-block-paragraph">Understanding OOP brings several benefits that enhance your coding experience:</p>



<ol class="wp-block-list">
<li><strong>Modularity</strong>: Like building different parts of a house separately, OOP allows you to write and maintain code in distinct, logical blocks.</li>



<li><strong>Reusability</strong>: Once a class is written, it can be reused to create countless objects, reducing redundancy and minimizing errors.</li>



<li><strong>Encapsulation</strong>: This principle hides the internal state of an object and requires all interactions to be performed through an object&#8217;s methods, reducing complexity and increasing security.</li>



<li><strong>Inheritance</strong>: Classes can inherit attributes and methods from other classes. This makes it easy to create and manage related classes without duplicating code. For example:</li>
</ol>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Puppy(Dog):  # Puppy class inherits from Dog class

    def __init__(self, name, age, breed, is_playful=True):

        super().__init__(name, age, breed)  # Call the constructor of the parent class

        self.is_playful = is_playful  # New attribute specific to Puppy

    def play(self):

        return f"{self.name} is playing!"</pre>



<h3 class="wp-block-heading"><strong>Real-World Application</strong></h3>



<p class="wp-block-paragraph">Imagine you&#8217;re developing software for a library. Using OOP, you could create classes for Book, Member, and Loan. Each class would have attributes relevant to what it represents (like title and author for Book) and methods to perform operations (like checkout for Loan). This approach simplifies your code, making it more readable, maintainable, and scalable.</p>



<p class="wp-block-paragraph">Here’s a simple example of what these classes might look like:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Book:

    def __init__(self, title, author):

        self.title = title

        self.author = author

class Member:

    def __init__(self, name, member_id):

        self.name = name

        self.member_id = member_id

class Loan:

    def __init__(self, book, member):

        self.book = book

        self.member = member

    def checkout(self):

        return f"{self.member.name} checked out '{self.book.title}' by {self.book.author}."</pre>



<h3 class="wp-block-heading"><strong>Embrace the Object-Oriented Way</strong></h3>



<p class="wp-block-paragraph">Understanding classes and objects is like receiving the keys to a powerful vehicle in programming. Start by defining simple classes, creating objects, and using methods. Experiment, build small projects, and watch as the pieces of the OOP puzzle fall into place.</p>



<p class="wp-block-paragraph">Remember, programming is as much about practice as it is about understanding concepts. So, roll up your sleeves, fire up your code editor, and start bringing your ideas to life—one class and one object at a time!</p>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		<enclosure url="https://sekol.ninja/wp-content/uploads/2024/10/DeClass.mp3" length="4613280" type="audio/mpeg" />

			</item>
		<item>
		<title>Mastering Object-Oriented Programming (OOP) in Python: Key Concepts, Explanations, and Examples</title>
		<link>https://sekol.ninja/mastering-object-oriented-programming-oop-in-python-key-concepts-explanations-and-examples/</link>
		
		<dc:creator><![CDATA[Michael Sekol]]></dc:creator>
		<pubDate>Tue, 29 Oct 2024 17:25:12 +0000</pubDate>
				<category><![CDATA[Intro to Programming]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://sekol.ninja/?p=1950</guid>

					<description><![CDATA[Object-Oriented Programming (OOP) is a fundamental programming paradigm that helps in organizing and structuring code in a modular, reusable way. By the [&#8230;]]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-audio"><audio controls src="https://sekol.ninja/wp-content/uploads/2024/10/objectorientedprogramming.mp3"></audio></figure>



<p class="wp-block-paragraph">Object-Oriented Programming (OOP) is a fundamental programming paradigm that helps in organizing and structuring code in a modular, reusable way. By the end of this guide, you’ll have a clearer understanding of OOP principles and how they work in Python. We’ll cover the following essential concepts:</p>



<ol class="wp-block-list">
<li><strong>Classes and Objects</strong></li>



<li><strong>Attributes and Methods</strong></li>



<li><strong>Encapsulation</strong></li>



<li><strong>Inheritance</strong></li>



<li><strong>Polymorphism</strong></li>
</ol>



<h2 class="wp-block-heading"><strong>1. Classes and Objects</strong></h2>



<h3 class="wp-block-heading"><strong>What is a Class?</strong></h3>



<p class="wp-block-paragraph">A <strong>class</strong> is like a blueprint for creating objects. Imagine you’re building a blueprint for a type of car. You would define properties (like color, make, model) and behaviors (like drive, stop). Each specific car is an <strong>object</strong> created from that blueprint.</p>



<p class="wp-block-paragraph">In programming, a class defines the properties (called <strong>attributes</strong>) and behaviors (called <strong>methods</strong>) of an object.</p>



<h3 class="wp-block-heading"><strong>What is an Object?</strong></h3>



<p class="wp-block-paragraph">An <strong>object</strong> is an instance of a class. It’s like a specific car built from the car blueprint. Each car has its unique attributes and can perform actions, like driving or stopping.</p>



<figure class="wp-block-image"><img decoding="async" src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfNmzFu4xm3KROu-iEcQ1HBZbwQMpV6GBBX5TLqRYdv7zx-ip9ohVb1kUQdtN_Pk_zoQE7aigI8PaFNsgA-0QUh3sRVmCdVzp32A92QoPt7RFk_SbdUSn_sp6_8kanwx3iuqpFQscVU5Mc6lqE9kw65MPg?key=9kzrfMnqV4a-cbtd-0d1VjCL" alt=""/></figure>



<h3 class="wp-block-heading"><strong>Example Code for Classes and Objects</strong></h3>



<p class="wp-block-paragraph">Here’s an example of a Car class in Python:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Car:
    # Constructor to initialize attributes
    def __init__(self, make, model, color):
        self.make = make       # Attribute
        self.model = model     # Attribute
        self.color = color     # Attribute
    
    # Method to describe the car
    def describe(self):
        return f"This car is a {self.color} {self.make} {self.model}."

# Creating objects (instances) of the Car class
car1 = Car("Toyota", "Corolla", "blue")
car2 = Car("Ford", "Mustang", "red")

# Using the describe method
print(car1.describe())   # Output: This car is a blue Toyota Corolla.
print(car2.describe())   # Output: This car is a red Ford Mustang.
</pre>



<h2 class="wp-block-heading"><strong>2. Attributes and Methods</strong></h2>



<ul class="wp-block-list">
<li><strong>Attributes</strong>: These are the variables that belong to an object and define its characteristics. For example, make, model, and color in the Car class.</li>



<li><strong>Methods</strong>: These are functions within a class that define behaviors for the object. For example, describe() in the Car class.</li>
</ul>



<h3 class="wp-block-heading"><strong>Example of Attributes and Methods in Python</strong></h3>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Book:
    def __init__(self, title, author, pages):
        self.title = title         # Attribute
        self.author = author       # Attribute
        self.pages = pages         # Attribute

    def read(self):                # Method
        return f"You're reading '{self.title}' by {self.author}."

# Create a book object
book1 = Book("The Great Gatsby", "F. Scott Fitzgerald", 218)

# Accessing attributes and methods
print(book1.title)          # Output: The Great Gatsby
print(book1.read())         # Output: You're reading 'The Great Gatsby' by F. Scott Fitzgerald.
</pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><strong>3. Encapsulation</strong></h2>



<p class="wp-block-paragraph"><strong>Encapsulation</strong> is about keeping data safe from outside modification by making attributes private. You can control access to an attribute by using <strong>getter</strong> and <strong>setter</strong> methods.</p>



<figure class="wp-block-image"><img decoding="async" src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeatN_JUnI6GfB3wtV3b6hrOIMOS7hyournwO1wxq_lsKabiZ2661qs5uRIWOMNUuz9bUeZbWLIXA1lxGrzuFmsdkW7bqTJQR375YtmrfQrjWdoDMMjo5Rj_Yo0IaPzrI5-RArGMSwf1m5WVkRSghrBav12?key=9kzrfMnqV4a-cbtd-0d1VjCL" alt=""/></figure>



<h3 class="wp-block-heading"><strong>Example Code for Encapsulation</strong></h3>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class BankAccount:
    def __init__(self, owner, balance):
        self.owner = owner              # Public attribute
        self.__balance = balance        # Private attribute
    
    # Getter for balance
    def get_balance(self):
        return self.__balance

    # Setter for balance
    def set_balance(self, amount):
        if amount >= 0:
            self.__balance = amount
        else:
            print("Invalid balance amount!")

# Testing encapsulation
account = BankAccount("Alice", 1000)
print(account.get_balance())  # Accessing private attribute via getter method

account.set_balance(2000)     # Modifying private attribute via setter method
print(account.get_balance())  # Output: 2000
</pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><strong>4. Inheritance</strong></h2>



<p class="wp-block-paragraph"><strong>Inheritance</strong> allows you to create a new class (child class) based on an existing class (parent class). The child class inherits the attributes and methods of the parent class but can also add its own or modify existing ones.</p>



<figure class="wp-block-image"><img decoding="async" src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe7rWbitH8sZm7WdX2967NOBD3Y29nR0rZ_ynlJ96YCUCSIiEQLoM64XsV71lYsgSaH9k3E67HXWY_aRXR-EsCkrn9TbHJPWH8cMoBC98ZZ0Xxc3j4MD2DEt_Qh5Ziopqq2hja-aoqnmyNOrnlp2XKyAYnB?key=9kzrfMnqV4a-cbtd-0d1VjCL" alt=""/></figure>



<h3 class="wp-block-heading"><strong>Example Code for Inheritance</strong></h3>



<p class="wp-block-paragraph">Let’s create a base class Animal and two derived classes Dog and Cat.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Animal:
    def __init__(self, name, species):
        self.name = name
        self.species = species
    
    def sound(self):
        return "This animal makes a sound."

# Dog class inherits from Animal
class Dog(Animal):
    def sound(self):  # Overriding method
        return "Woof woof!"

# Cat class inherits from Animal
class Cat(Animal):
    def sound(self):  # Overriding method
        return "Meow!"

# Testing Inheritance
dog = Dog("Buddy", "Dog")
cat = Cat("Whiskers", "Cat")

print(dog.sound())   # Output: Woof woof!
print(cat.sound())   # Output: Meow!
</pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><strong>5. Polymorphism</strong></h2>



<p class="wp-block-paragraph"><strong>Polymorphism</strong> means “many forms.” In OOP, it allows you to use a single method in different ways based on the context. For example, different classes can have their own version of a method with the same name, like sound() in our Dog and Cat classes above.<img decoding="async" src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe0t4VWljocz1_GU_C1q0uSRlLGoYPFuePxD9XMjaK0y5Eq0aC1jzx-PivxQZJKA8aIM7q0R7dk76PbK_zHGuiD67U4BPWJZgpGWiXh_wGC_I3n26CK7NWbtppuDLy0Y-y1KNtaerj758wNKgvtpiRHAXUZ?key=9kzrfMnqV4a-cbtd-0d1VjCL" width="624" height="356"></p>



<h3 class="wp-block-heading"><strong>Example Code for Polymorphism</strong></h3>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">def make_animal_sound(animal):
    print(animal.sound())

make_animal_sound(dog)  # Output: Woof woof!
make_animal_sound(cat)  # Output: Meow!
</pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><strong>6. Constructors and the </strong><strong>__init__</strong><strong> Method</strong></h2>



<p class="wp-block-paragraph">The __init__ method in Python is a <strong>constructor</strong> that runs automatically whenever you create a new object. It helps initialize the object’s attributes.</p>



<h3 class="wp-block-heading"><strong>Example Code Using </strong><strong>__init__</strong></h3>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def introduce(self):
        return f"Hello, I'm {self.name} and I'm {self.age} years old."

person1 = Person("Alice", 30)
print(person1.introduce())  # Output: Hello, I'm Alice and I'm 30 years old.
</pre>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading"><strong>7. Putting It All Together</strong></h2>



<p class="wp-block-paragraph">To reinforce these concepts, here’s a cohesive example that incorporates <strong>encapsulation, inheritance, and polymorphism</strong>. Let’s create a simple game where each character is a different kind of Avatar.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class Avatar:
    def __init__(self, name, element):
        self.name = name
        self.element = element
    
    def power(self):
        return "This Avatar controls the elements."

# Airbender inherits from Avatar and overrides power method
class Airbender(Avatar):
    def power(self):
        return f"{self.name} uses Airbending to control air!"

# Firebender inherits from Avatar and overrides power method
class Firebender(Avatar):
    def power(self):
        return f"{self.name} uses Firebending to control fire!"

# Polymorphism in action
def display_avatar_power(avatar):
    print(avatar.power())

# Create instances of different Avatars
aang = Airbender("Aang", "Air")
zuko = Firebender("Zuko", "Fire")

display_avatar_power(aang)  # Output: Aang uses Airbending to control air!
display_avatar_power(zuko)  # Output: Zuko uses Firebending to control fire!
</pre>



<h3 class="wp-block-heading"><strong>Final Example Code</strong></h3>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading"><strong>Summary</strong></h3>



<ul class="wp-block-list">
<li><strong>Classes and Objects</strong>: Fundamental building blocks of OOP, allowing you to model real-world entities.</li>



<li><strong>Attributes and Methods</strong>: Properties and behaviors within a class.</li>



<li><strong>Encapsulation</strong>: Keeps data safe and controls access using methods.</li>



<li><strong>Inheritance</strong>: Allows classes to share attributes and methods.</li>



<li><strong>Polymorphism</strong>: Enables different classes to use the same method name with different behaviors.</li>
</ul>



<p class="wp-block-paragraph">I encourage you students to try building your own classes and experiment with inheritance, polymorphism, and encapsulation to gain a solid grasp of these OOP principles!</p>



<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
		
		<enclosure url="https://sekol.ninja/wp-content/uploads/2024/10/objectorientedprogramming.mp3" length="4438080" type="audio/mpeg" />

			</item>
		<item>
		<title>Unlock Free Codecademy Pro Access via Clever.com: A Step-by-Step Guide for Teachers &#038; Students</title>
		<link>https://sekol.ninja/unlock-free-codecademy-pro-access-via-clever-com-a-step-by-step-guide-for-teachers-students/</link>
		
		<dc:creator><![CDATA[Sekol AI Bot]]></dc:creator>
		<pubDate>Sun, 11 Aug 2024 18:40:51 +0000</pubDate>
				<category><![CDATA[Intro to Programming]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Learning to Code]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Codecademy]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Learn to Code]]></category>
		<category><![CDATA[LinkedIn Learning]]></category>
		<guid isPermaLink="false">https://sekol.ninja/?p=2332</guid>

					<description><![CDATA[Whether you’re a student eager to dive into Python or a teacher looking to enrich your classroom with hands-on coding, Codecademy Pro [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Whether you’re a student eager to dive into Python or a teacher looking to enrich your classroom with hands-on coding, Codecademy Pro is a great resource to empower your students to learn Computer Science skills. Worried about pricing? Did you know that most Ohio school districts already have access to <strong>Clever.com</strong>? Through Clever’s seamless single sign-on, educators can add <strong>Codecademy</strong> to their district’s app library—granting students <strong>free Pro access</strong> to Codecademy’s entire course catalog. Here’s how you and your students can get started today.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Why Codecademy Pro Matters</h2>



<ul class="wp-block-list">
<li><strong>Interactive Learning</strong>: Codecademy Pro’s hands-on exercises, quizzes, and real-world projects accelerate coding fluency.</li>



<li><strong>Career-Ready Paths</strong>: From the Computer Science Career Path (Python, data structures, algorithms) to Web Development tracks (HTML/CSS/JavaScript), students can follow guided curricula that mirror industry workflows.</li>



<li><strong>Built-In Certificates</strong>: Upon completion of a path, students earn shareable certificates—perfect for resumes or college applications.</li>



<li><strong>Teacher Dashboard</strong>: Educators can track student progress, assign exercises, and identify areas for extra support.</li>
</ul>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="585" src="https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1-1024x585.jpg" alt="" class="wp-image-2336" srcset="https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1-1024x585.jpg 1024w, https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1-300x171.jpg 300w, https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1-768x439.jpg 768w, https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1-1000x571.jpg 1000w, https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1-230x131.jpg 230w, https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1-350x200.jpg 350w, https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1-480x274.jpg 480w, https://sekol.ninja/wp-content/uploads/2025/06/codecademy-1.jpg 1500w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Teacher Prerequisite: Adding Codecademy to Clever</h2>



<p class="wp-block-paragraph"><em>(Only needs to be done once per district or school. Reach out to your technology or curriculum coordinator if you don’t have admin rights.)</em></p>



<ol class="wp-block-list">
<li><strong>Log in to Clever.com</strong> as an administrator or teacher with app-management permissions.</li>



<li>Browse the <strong>Clever Application Library</strong> and search for “Codecademy.”</li>



<li>Click <strong>Add</strong> to include Codecademy in your district’s or school’s single-sign-on portal.</li>



<li><strong>Publish</strong> the change; students will now see the Codecademy icon on their Clever dashboard.</li>
</ol>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><strong>Tip for Admins</strong>: If you don’t see “Codecademy” in the library, reach out to your district Clever support or submit a request through the Clever help center.</p>
</blockquote>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="585" src="https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage-1024x585.jpg" alt="" class="wp-image-2337" srcset="https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage-1024x585.jpg 1024w, https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage-300x171.jpg 300w, https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage-768x439.jpg 768w, https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage-1000x571.jpg 1000w, https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage-230x131.jpg 230w, https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage-350x200.jpg 350w, https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage-480x274.jpg 480w, https://sekol.ninja/wp-content/uploads/2025/06/cleversekolpage.jpg 1500w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Part 1: Student Sign-On via Clever</h2>



<ol class="wp-block-list">
<li><strong>Go to</strong> <a class="" href="https://www.clever.com/">https://www.clever.com/</a></li>



<li>Click <strong>Log in as a Student</strong>.</li>



<li>Start typing your school name (e.g., “Mahoning…”); select your district when it appears.</li>



<li>Choose <strong>Log in with Google</strong> (use your school-issued Gmail/Google Workspace account).</li>



<li>From your Clever dashboard, click <strong>M. Sekol’s Page</strong> (or your teacher’s Clever page).</li>



<li>Click the <strong>Codecademy</strong> icon—Clever will automatically log you in to your <strong>Pro</strong> account.</li>
</ol>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Part 2: Enrolling in the Computer Science Pathway</h2>



<ol class="wp-block-list">
<li>Once inside Codecademy, select <strong>Catalog</strong> from the top navigation.</li>



<li>Click <strong>Computer Science</strong> under course categories.</li>



<li>Scroll to the <strong>Career Path: Computer Science</strong> tile.</li>



<li>Hit the <strong>Start</strong> button (it’s usually bright yellow!).</li>



<li>You’re now enrolled in the <strong>Computer Science Pathway</strong>, featuring foundational Python, data structures, algorithms, and more.</li>
</ol>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><strong>Congratulations!</strong> You now have access to hundreds of hours of coding content—completely free through your school’s Clever integration.</p>
</blockquote>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Exploring Beyond Python</h2>



<p class="wp-block-paragraph">While the Computer Science Pathway is a fantastic launchpad, Codecademy Pro offers much more:</p>



<ul class="wp-block-list">
<li><strong>Web Development</strong>: HTML, CSS, JavaScript, React, Node.js</li>



<li><strong>Data Science</strong>: SQL, pandas, data visualization</li>



<li><strong>Cybersecurity</strong>: Fundamental security principles, encryption, penetration testing</li>



<li><strong>Mobile Development</strong>: Swift, Kotlin</li>
</ul>



<p class="wp-block-paragraph">Encourage students to browse the <strong>Catalog</strong>, bookmark courses they’re curious about, and even pursue multiple pathways over the school year.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Submission &amp; Classroom Accountability</h2>



<p class="wp-block-paragraph">To verify successful sign-up and pathway enrollment, ask students to:</p>



<ol class="wp-block-list">
<li>Click their <strong>profile icon</strong> in the top-right corner.</li>



<li>Take a screenshot showing their name and <strong>“Pro”</strong> status.</li>



<li>Navigate to the <strong>Computer Science Pathway</strong> page and screenshot the pathway banner.</li>



<li>Submit both screenshots via Google Classroom (or your LMS of choice).</li>
</ol>



<p class="wp-block-paragraph">This quick check ensures everyone is properly enrolled—and gives you a chance to celebrate your students’ new coding capabilities!</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Tips for Teachers</h2>



<ul class="wp-block-list">
<li><strong>Integrate Codecademy Assignments</strong>: Assign specific lessons as homework or in-class labs.</li>



<li><strong>Host “Coding Hours”</strong>: Set aside one period a week for students to work together and troubleshoot common roadblocks.</li>



<li><strong>Share Real-World Projects</strong>: Challenge students to build a small app—like a quiz or a weather dashboard—using skills from their Codecademy pathway.</li>



<li><strong>Track Progress</strong>: Use the Codecademy teacher dashboard to identify students who might need extra help or those ready for extension activities.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Ready to Get Coding?</h2>



<p class="wp-block-paragraph">By leveraging your district’s existing Clever portal, you can unlock free, unlimited access to <strong>Codecademy Pro</strong>—empowering every student in your classroom to become the coder of tomorrow. Reach out to your tech coordinator today, add Codecademy to your Clever library, and watch your students thrive as they master Python, JavaScript, and beyond.</p>



<p class="wp-block-paragraph"><em>Happy coding!</em></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: sekol.ninja @ 2026-06-17 07:39:20 by W3 Total Cache
-->