Code viewer for World: Lesson 2
document.write(`

<style>
  body {
    font-family: Arial, sans-serif;
    background: #ffffff;
    color: #222;
    max-width: 750px;
    margin: 0 auto;
    padding: 30px 20px;
    line-height: 1.7;
    font-size: 15px;
  }

  h1 { font-size: 1.5rem; border-bottom: 2px solid #222; padding-bottom: 8px; margin-bottom: 24px; }
  h2 { font-size: 1.1rem; margin-top: 36px; margin-bottom: 8px; color: #111; }

  p { margin-bottom: 10px; }

  pre {
    background: #f4f4f4;
    border-left: 4px solid #555;
    padding: 14px 18px;
    font-family: 'Courier New', monospace;
    font-size: 0.88rem;
    line-height: 1.7;
    overflow-x: auto;
    margin: 12px 0;
  }

  code {
    background: #f0f0f0;
    padding: 1px 5px;
    font-family: 'Courier New', monospace;
    font-size: 0.88rem;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.91rem;
  }

  th {
    background: #222;
    color: #fff;
    padding: 8px 12px;
    text-align: left;
  }

  td {
    padding: 8px 12px;
    border-bottom: 1px solid #ddd;
  }

  tr:nth-child(even) td { background: #f9f9f9; }

  hr { border: none; border-top: 1px solid #ddd; margin: 36px 0; }

  .activity {
    margin-top: 16px;
  }

  .activity p {
    font-weight: bold;
    margin-bottom: 6px;
  }
</style>

<h1>Lesson 2 &mdash; Conditional Execution</h1>


<h2>Boolean Expressions</h2>
<p>A boolean expression is a question that Python answers with either <code>True</code> or <code>False</code>.
You compare two values using a <strong>comparison operator</strong>:</p>
<table>
  <tr><th>Operator</th><th>Meaning</th><th>Example</th><th>Result</th></tr>
  <tr><td><code>==</code></td><td>Equal to</td>                <td><code>5 == 5</code></td>  <td>True</td></tr>
  <tr><td><code>!=</code></td><td>Not equal to</td>            <td><code>5 != 3</code></td>  <td>True</td></tr>
  <tr><td><code>&lt;</code></td> <td>Less than</td>            <td><code>3 &lt; 5</code></td>   <td>True</td></tr>
  <tr><td><code>&gt;</code></td> <td>Greater than</td>         <td><code>5 &gt; 3</code></td>   <td>True</td></tr>
  <tr><td><code>&lt;=</code></td><td>Less than or equal</td>   <td><code>3 &lt;= 3</code></td>  <td>True</td></tr>
  <tr><td><code>&gt;=</code></td><td>Greater than or equal</td><td><code>4 &gt;= 5</code></td>  <td>False</td></tr>
</table>
<p>Note: <code>==</code> checks if two values are equal. A single <code>=</code> is used to assign a variable &mdash; they are not the same thing.</p>

<div class="activity">
  <p>Activity 1:</p>
  ` + AB.launchWorld( "5685604394", "Activity 1" ) + `
</div>

<hr>


<h2>The if Statement</h2>
<p>An <code>if</code> statement lets your program make a decision. The indented code underneath only runs if the condition is <code>True</code>. Python uses <strong>indentation</strong> (4 spaces) to know which lines belong inside the <code>if</code>.</p>
<pre>x = 10

if x > 5:
    print("x is greater than 5")

print("this always runs")</pre>
<p>If <code>x</code> were 3, the first print would be skipped entirely. The second print runs regardless because it is not indented.</p>

<div class="activity">
  <p>Activity 2:</p>
  ` + AB.launchWorld( "4535636286", "Activity 2" ) + `
</div>

<hr>


<h2>if / else</h2>
<p>An <code>else</code> block runs when the <code>if</code> condition is <code>False</code>. Exactly one of the two blocks will always run.</p>
<pre>age = 16

if age >= 18:
    print("You can vote.")
else:
    print("You are too young to vote.")</pre>

<div class="activity">
  <p>Activity 3:</p>
  ` + AB.launchWorld( "7257212540", "Activity 3" ) + `
</div>

<hr>


<h2>if / elif / else</h2>
<p><code>elif</code> (short for "else if") lets you check multiple conditions in sequence. Python works through them top to bottom and runs the first one that is <code>True</code>. The <code>else</code> at the end catches everything that did not match.</p>
<pre>score = 72

if score >= 90:
    print("Grade: A")
elif score >= 80:
    print("Grade: B")
elif score >= 70:
    print("Grade: C")
elif score >= 60:
    print("Grade: D")
else:
    print("Grade: F")</pre>
<p>You can have as many <code>elif</code> blocks as you need. The <code>else</code> is optional but good practice.</p>

<div class="activity">
  <p>Activity 4:</p>
  ` + AB.launchWorld( "7638696505", "Activity 4" ) + `
</div>

<hr>


<h2>Indentation</h2>
<p>Python uses indentation to define which lines of code belong inside a block. Every line inside an <code>if</code>, <code>elif</code>, or <code>else</code> must be indented by the same amount &mdash; 4 spaces is the standard. Getting indentation wrong is one of the most common errors beginners make.</p>
<pre># Correct
if True:
    print("indented correctly")

# This will cause an IndentationError
if True:
print("not indented -- Python will crash")</pre>

<hr>


<h2>Nested Conditions</h2>
<p>You can place an <code>if</code> statement inside another <code>if</code> statement. Each level of nesting adds another 4 spaces of indentation.</p>
<pre>age = 20
has_id = True

if age >= 18:
    if has_id:
        print("Entry allowed.")
    else:
        print("You need ID.")
else:
    print("You are under 18.")</pre>
<p>Nested conditions work, but they can become hard to read quickly. The <code>and</code> / <code>or</code> keywords (below) are often a cleaner alternative.</p>

<hr>


<h2>Logical Operators &mdash; and, or, not</h2>
<p>You can combine boolean expressions using logical operators:</p>
<table>
  <tr><th>Operator</th><th>Meaning</th><th>Example</th><th>Result</th></tr>
  <tr><td><code>and</code></td><td>Both must be True</td>  <td><code>age &gt;= 18 and has_id</code></td><td>True only if both are True</td></tr>
  <tr><td><code>or</code></td> <td>At least one True</td>  <td><code>x &lt; 0 or x &gt; 100</code></td> <td>True if either is True</td></tr>
  <tr><td><code>not</code></td><td>Flips True / False</td> <td><code>not has_id</code></td>              <td>True if has_id is False</td></tr>
</table>
<pre>age    = 20
has_id = True

if age >= 18 and has_id:
    print("Entry allowed.")
else:
    print("Entry refused.")</pre>

<div class="activity">
  <p>Activity 5:</p>
  ` + AB.launchWorld( "8473540277", "Activity 5" ) + `
</div>

<hr>


<h2>try / except</h2>
<p>When you ask a user for a number using <code>input()</code>, the program will crash if they type something that is not a number. A <code>try</code> / <code>except</code> block lets you handle that error gracefully instead of crashing.</p>
<pre>raw = await input("Enter a number: ")

try:
    number = int(raw)
    print("You entered:", number)
except:
    print("That was not a valid number.")</pre>
<p>Python <em>tries</em> the code inside the <code>try</code> block. If anything goes wrong, it jumps to the <code>except</code> block instead of crashing.</p>

<div class="activity">
  <p>Activity 6:</p>
  ` + AB.launchWorld( "8437025086", "Activity 6" ) + `
</div>

<hr>


<h2>Exercise</h2>
<p>Now put everything from this lesson together. The exercise world below will give you a problem to solve using boolean expressions, conditionals, logical operators, and try/except.</p>

<div class="activity">
  <p>Activity 7:</p>
  ` + AB.launchWorld( "0779541296", "Activity 7" ) + `
</div>

`);