Conditional statements let your program make decisions. It checks if a certain condition is true — and then runs some code based on that. If the condition is not true, it can check another condition, or just run a default block of code.
It’s like saying:
“If it's raining, take an umbrella. Else if it's cloudy, take a jacket. Else, wear whatever you want.”
🔹 Python Syntax Breakdown
if condition:
# Block A
elif another_condition:
# Block B
else:
# Block C🔸 if block:
<div class="infographic-jsifonly">
<style>
.infographic-jsifonly {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--ok: #1a7f4e;
--ok-soft: #e3f5ec;
--display-font: 'Fraunces', Georgia, serif;
--body-font: 'Inter', -apple-system, sans-serif;
--mono-font: 'IBM Plex Mono', 'Courier New', monospace;
max-width: 520px;
margin: 0 auto;
box-sizing: border-box;
font-family: var(--body-font);
color: var(--ink);
background: var(--paper);
}
.infographic-jsifonly[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--ok: #5cd6a0;
--ok-soft: #16342a;
}
.infographic-jsifonly * { box-sizing: border-box; }
.infographic-jsifonly .ig-inner { padding: 1.75rem clamp(1.25rem, 5vw, 3rem) 2rem; }
.infographic-jsifonly .ig-title {
font-family: var(--display-font); font-size: clamp(1.4rem, 4.5vw, 1.9rem);
font-weight: 600; text-align: center;
}
.infographic-jsifonly .controls { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.infographic-jsifonly .input-wrap { position: relative; }
.infographic-jsifonly .input-tag {
position: absolute; top: -1.35rem; left: 50%; transform: translateX(-50%);
font-size: 0.65rem; font-family: var(--mono-font); color: var(--accent);
background: var(--accent-soft); padding: 0.1rem 0.45rem; border-radius: 4px; white-space: nowrap;
}
.infographic-jsifonly .age-input {
width: 6rem; height: 2.6rem; font-family: var(--mono-font); font-size: 1.1rem; font-weight: 700;
text-align: center; padding: 0 0.4rem; border: 1px solid var(--line); background: var(--paper-alt);
color: var(--ink); outline: none;
}
.infographic-jsifonly .age-input:focus { border-color: var(--accent); }
.infographic-jsifonly .presets { display: flex; gap: 0.4rem; justify-content: center; width: 100%; }
.infographic-jsifonly .preset-btn {
font: inherit; font-size: 0.75rem; font-family: var(--mono-font); border: 1px dashed var(--line);
background: var(--paper); color: var(--ink-soft); padding: 0.3rem 0.65rem; border-radius: 4px; cursor: pointer;
}
.infographic-jsifonly .preset-btn:hover { border-color: var(--accent); color: var(--accent); }
.infographic-jsifonly .stage { display: flex; justify-content: center; }
.infographic-jsifonly .stage svg { width: 100%; max-width: 420px; height: auto; overflow: visible; }
.infographic-jsifonly .fc-shape { fill: var(--paper-alt); stroke: var(--line); stroke-width: 1.8; transition: fill 0.2s, stroke 0.2s; }
.infographic-jsifonly .fc-shape.reached-yes { fill: var(--accent-soft); stroke: var(--accent); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsifonly .fc-shape.reached-no { fill: var(--paper-alt); stroke: var(--accent); }
.infographic-jsifonly .fc-block.reached { fill: var(--ok-soft); stroke: var(--ok); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsifonly .fc-pill { fill: var(--accent-soft); stroke: var(--accent); }
.infographic-jsifonly .fc-text { font-family: var(--mono-font); font-size: 12px; fill: var(--ink); text-anchor: middle; }
.infographic-jsifonly .fc-text.on-pill { fill: var(--accent); font-weight: 700; }
.infographic-jsifonly .fc-text.on-block { font-weight: 700; }
.infographic-jsifonly .fc-mark { font-family: var(--mono-font); font-size: 13px; font-weight: 700; text-anchor: middle; }
.infographic-jsifonly .fc-mark.yes { fill: var(--accent); }
.infographic-jsifonly .fc-mark.no { fill: var(--ink-soft); }
.infographic-jsifonly .fc-edge path { stroke: var(--line); stroke-width: 2; fill: none; transition: stroke 0.2s; }
.infographic-jsifonly .fc-edge polygon { fill: var(--line); transition: fill 0.2s; }
.infographic-jsifonly .fc-edge.is-check path { stroke: var(--accent); stroke-width: 2.5; }
.infographic-jsifonly .fc-edge.is-check polygon { fill: var(--accent); }
.infographic-jsifonly .fc-edge.is-taken path { stroke: var(--ok); stroke-width: 2.5; }
.infographic-jsifonly .fc-edge.is-taken polygon { fill: var(--ok); }
.infographic-jsifonly .junction { fill: var(--line); transition: fill 0.2s; }
.infographic-jsifonly .junction.is-taken { fill: var(--ok); }
.infographic-jsifonly .caption {
text-align: center; font-size: 0.9rem; color: var(--ink-soft);
}
.infographic-jsifonly .caption strong { color: var(--ink); font-family: var(--mono-font); }
@media (prefers-reduced-motion: reduce) {
.infographic-jsifonly *, .infographic-jsifonly *::before, .infographic-jsifonly *::after {
animation-duration: 0.001ms !important; transition-duration: 0.001ms !important;
}
}
</style>
<div class="ig-inner">
<h2 class="ig-title">The if Statement</h2>
<div class="controls">
<div class="input-wrap">
<span class="input-tag">age</span>
<input type="number" class="age-input" id="ageInput" value="20" min="0" max="120">
</div>
<div class="presets">
<button class="preset-btn" data-v="25">25</button>
<button class="preset-btn" data-v="15">15</button>
</div>
</div>
<div class="stage">
<svg viewBox="0 0 480 470" xmlns="http://www.w3.org/2000/svg">
<!-- Start -->
<g id="n-start">
<rect class="fc-shape fc-pill" x="100" y="10" width="140" height="42" rx="21"></rect>
<text class="fc-text on-pill" x="170" y="36">Start</text>
</g>
<!-- Start -> Diamond -->
<g class="fc-edge" id="e-start-d">
<path d="M170,52 L170,79"></path>
<polygon points="170,85 165,75 175,75"></polygon>
</g>
<!-- Diamond -->
<g id="n-d">
<polygon class="fc-shape" points="170,85 250,140 170,195 90,140"></polygon>
<text class="fc-text" x="170" y="136">age >=</text>
<text class="fc-text" x="170" y="150">18 ?</text>
<text class="fc-mark" id="mark-d" x="204" y="105"></text>
</g>
<!-- Yes -> Block -->
<g class="fc-edge" id="e-d-yes">
<path d="M250,140 L263,140"></path>
<polygon points="270,140 260,135 260,145"></polygon>
</g>
<text class="fc-text" x="256" y="130" font-size="10" fill="var(--ink-soft)">yes</text>
<g id="n-block">
<rect class="fc-shape fc-block" x="270" y="115" width="120" height="50" rx="8"></rect>
<text class="fc-text on-block" x="330" y="141">Can vote</text>
<text class="fc-text" x="330" y="155" font-size="9" fill="var(--ink-soft)">(if block)</text>
</g>
<!-- No -> straight down, skipping the block -->
<g class="fc-edge" id="e-d-no">
<path d="M170,195 L170,334"></path>
</g>
<text class="fc-text" x="186" y="230" font-size="10" fill="var(--ink-soft)">no</text>
<!-- Block -> down -> left -> junction -->
<g class="fc-edge" id="e-block-merge">
<path d="M330,165 L330,340 L170,340"></path>
</g>
<!-- Junction dot -->
<circle class="junction" id="junction" cx="170" cy="340" r="4.5"></circle>
<!-- Junction -> End -->
<g class="fc-edge" id="e-merge-end">
<path d="M170,340 L170,384"></path>
<polygon points="170,390 165,380 175,380"></polygon>
</g>
<!-- End -->
<g id="n-end">
<rect class="fc-shape fc-pill" x="100" y="390" width="140" height="42" rx="21"></rect>
<text class="fc-text on-pill" x="170" y="416">End</text>
</g>
</svg>
</div>
<p class="caption" id="caption"></p>
</div>
</div>
<script>
(function () {
const wrapper = document.currentScript.closest('.infographic-jsifonly')
|| document.querySelector('.infographic-jsifonly');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
const input = wrapper.querySelector('#ageInput');
const caption = wrapper.querySelector('#caption');
const d = wrapper.querySelector('#n-d .fc-shape');
const mark = wrapper.querySelector('#mark-d');
const block = wrapper.querySelector('#n-block .fc-block');
const junction = wrapper.querySelector('#junction');
const eStartD = wrapper.querySelector('#e-start-d');
const eYes = wrapper.querySelector('#e-d-yes');
const eNo = wrapper.querySelector('#e-d-no');
const eBlockMerge = wrapper.querySelector('#e-block-merge');
const eMergeEnd = wrapper.querySelector('#e-merge-end');
const allEdges = [eStartD, eYes, eNo, eBlockMerge, eMergeEnd];
function reset() {
d.classList.remove('reached-yes', 'reached-no');
mark.textContent = ''; mark.classList.remove('yes', 'no');
block.classList.remove('reached');
junction.classList.remove('is-taken');
allEdges.forEach(e => e.classList.remove('is-check', 'is-taken'));
}
function update() {
reset();
const age = Number(input.value);
eStartD.classList.add('is-check');
if (age >= 18) {
d.classList.add('reached-yes');
mark.textContent = '✓'; mark.classList.add('yes');
eYes.classList.add('is-check');
block.classList.add('reached');
eBlockMerge.classList.add('is-taken');
eMergeEnd.classList.add('is-taken');
junction.classList.add('is-taken');
caption.innerHTML = `<strong>age = ${isNaN(age) ? '?' : age}</strong> → condition true, block runs`;
} else {
d.classList.add('reached-no');
mark.textContent = '✗'; mark.classList.add('no');
eNo.classList.add('is-taken');
eMergeEnd.classList.add('is-taken');
junction.classList.add('is-taken');
caption.innerHTML = `<strong>age = ${isNaN(age) ? '?' : age}</strong> → condition false, block skipped`;
}
}
input.addEventListener('input', update);
wrapper.querySelectorAll('.preset-btn').forEach(btn => {
btn.addEventListener('click', () => { input.value = btn.dataset.v; update(); });
});
update();
})();
</script>The program checks this first condition.
If it's True, it runs Block A, and skips the rest.
if temperature > 30:
print("It's hot!")🔸 elif block:
<div class="infographic-jsifei">
<style>
.infographic-jsifei {
--ink: #1a1a1a;
--ink-soft: #5c5c5c;
--paper: #ffffff;
--paper-alt: #f0ece4;
--accent: #2563eb;
--accent-soft:#e3ebfd;
--line: #ddd6c9;
--ok: #1a7f4e;
--ok-soft: #e3f5ec;
--display-font: 'Fraunces', Georgia, serif;
--body-font: 'Inter', -apple-system, sans-serif;
--mono-font: 'IBM Plex Mono', 'Courier New', monospace;
max-width: 620px;
margin: 0 auto;
box-sizing: border-box;
font-family: var(--body-font);
color: var(--ink);
background: var(--paper);
}
.infographic-jsifei[data-theme="dark"] {
--ink: #e8e6e1;
--ink-soft: #9a968c;
--paper: #121212;
--paper-alt: #1e1e26;
--accent: #5b8def;
--accent-soft:#202942;
--line: #2c313d;
--ok: #5cd6a0;
--ok-soft: #16342a;
}
.infographic-jsifei * { box-sizing: border-box; }
.infographic-jsifei .ig-inner { padding: 1.75rem clamp(1.25rem, 5vw, 3rem) 2rem; }
.infographic-jsifei .ig-title {
font-family: var(--display-font); font-size: clamp(1.4rem, 4.5vw, 1.9rem);
font-weight: 600; text-align: center; margin: 0 0 2.25rem;
}
.infographic-jsifei .controls { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.infographic-jsifei .input-wrap { position: relative; }
.infographic-jsifei .input-tag {
position: absolute; top: -1.35rem; left: 50%; transform: translateX(-50%);
font-size: 0.65rem; font-family: var(--mono-font); color: var(--accent);
background: var(--accent-soft); padding: 0.1rem 0.45rem; border-radius: 4px; white-space: nowrap;
}
.infographic-jsifei .score-input {
width: 6rem; height: 2.6rem; font-family: var(--mono-font); font-size: 1.1rem; font-weight: 700;
text-align: center; padding: 0 0.4rem; border: 1px solid var(--line); background: var(--paper-alt);
color: var(--ink); outline: none;
}
.infographic-jsifei .score-input:focus { border-color: var(--accent); }
.infographic-jsifei .presets { display: flex; gap: 0.4rem; justify-content: center; margin-top: 1.6rem; width: 100%; }
.infographic-jsifei .preset-btn {
font: inherit; font-size: 0.75rem; font-family: var(--mono-font); border: 1px dashed var(--line);
background: var(--paper); color: var(--ink-soft); padding: 0.3rem 0.65rem; border-radius: 4px; cursor: pointer;
}
.infographic-jsifei .preset-btn:hover { border-color: var(--accent); color: var(--accent); }
.infographic-jsifei .stage { margin-top: 1.5rem; display: flex; justify-content: center; }
.infographic-jsifei .stage svg { width: 100%; max-width: 500px; height: auto; overflow: visible; }
.infographic-jsifei .fc-shape { fill: var(--paper-alt); stroke: var(--line); stroke-width: 1.8; transition: fill 0.2s, stroke 0.2s; }
.infographic-jsifei .fc-shape.reached-yes { fill: var(--accent-soft); stroke: var(--accent); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsifei .fc-shape.reached-no { fill: var(--paper-alt); stroke: var(--accent); }
.infographic-jsifei .fc-block.reached { fill: var(--ok-soft); stroke: var(--ok); filter: drop-shadow(0 3px 6px rgba(0,0,0,0.15)); }
.infographic-jsifei .fc-pill { fill: var(--accent-soft); stroke: var(--accent); }
.infographic-jsifei .fc-text { font-family: var(--mono-font); font-size: 12px; fill: var(--ink); text-anchor: middle; }
.infographic-jsifei .fc-text.on-pill { fill: var(--accent); font-weight: 700; }
.infographic-jsifei .fc-text.on-block { font-weight: 700; }
.infographic-jsifei .fc-mark { font-family: var(--mono-font); font-size: 13px; font-weight: 700; text-anchor: middle; }
.infographic-jsifei .fc-mark.yes { fill: var(--accent); }
.infographic-jsifei .fc-mark.no { fill: var(--ink-soft); }
.infographic-jsifei .fc-edge path { stroke: var(--line); stroke-width: 2; fill: none; transition: stroke 0.2s; }
.infographic-jsifei .fc-edge polygon { fill: var(--line); transition: fill 0.2s; }
.infographic-jsifei .fc-edge.is-check path { stroke: var(--accent); stroke-width: 2.5; }
.infographic-jsifei .fc-edge.is-check polygon { fill: var(--accent); }
.infographic-jsifei .fc-edge.is-taken path { stroke: var(--ok); stroke-width: 2.5; }
.infographic-jsifei .fc-edge.is-taken polygon { fill: var(--ok); }
.infographic-jsifei .junction { fill: var(--line); transition: fill 0.2s; }
.infographic-jsifei .junction.is-taken { fill: var(--ok); }
.infographic-jsifei .caption {
text-align: center; font-size: 0.9rem; color: var(--ink-soft); margin-top: 1.25rem;
}
.infographic-jsifei .caption strong { color: var(--ink); font-family: var(--mono-font); }
@media (prefers-reduced-motion: reduce) {
.infographic-jsifei *, .infographic-jsifei *::before, .infographic-jsifei *::after {
animation-duration: 0.001ms !important; transition-duration: 0.001ms !important;
}
}
</style>
<div class="ig-inner">
<h2 class="ig-title">The if...else if...else Statement</h2>
<div class="controls">
<div class="input-wrap">
<span class="input-tag">score</span>
<input type="number" class="score-input" id="scoreInput" value="75" min="0" max="100">
</div>
<div class="presets">
<button class="preset-btn" data-v="95">95</button>
<button class="preset-btn" data-v="72">72</button>
<button class="preset-btn" data-v="45">45</button>
</div>
</div>
<div class="stage">
<svg viewBox="0 0 560 670" xmlns="http://www.w3.org/2000/svg">
<!-- Start -->
<g id="n-start">
<rect class="fc-shape fc-pill" x="135" y="10" width="140" height="42" rx="21"></rect>
<text class="fc-text on-pill" x="205" y="36">Start</text>
</g>
<!-- Start -> Diamond 1 -->
<g class="fc-edge" id="e-start-d1">
<path d="M205,52 L205,79"></path>
<polygon points="205,85 200,75 210,75"></polygon>
</g>
<!-- Diamond 1 -->
<g id="n-d1">
<polygon class="fc-shape" points="205,85 285,140 205,195 125,140"></polygon>
<text class="fc-text" x="205" y="136">score</text>
<text class="fc-text" x="205" y="150">>= 90 ?</text>
<text class="fc-mark" id="mark-d1" x="239" y="105"></text>
</g>
<!-- Yes1 -> Block A -->
<g class="fc-edge" id="e-d1-yes">
<path d="M285,140 L298,140"></path>
<polygon points="305,140 295,135 295,145"></polygon>
</g>
<text class="fc-text" x="291" y="130" font-size="10" fill="var(--ink-soft)">yes</text>
<g id="n-blockA">
<rect class="fc-shape fc-block" x="305" y="115" width="130" height="50" rx="8"></rect>
<text class="fc-text on-block" x="370" y="146">Grade A</text>
</g>
<!-- No1 -> Diamond 2 -->
<g class="fc-edge" id="e-d1-no">
<path d="M205,195 L205,269"></path>
<polygon points="205,275 200,265 210,265"></polygon>
</g>
<text class="fc-text" x="221" y="240" font-size="10" fill="var(--ink-soft)">no</text>
<!-- Diamond 2 -->
<g id="n-d2">
<polygon class="fc-shape" points="205,275 285,330 205,385 125,330"></polygon>
<text class="fc-text" x="205" y="326">score</text>
<text class="fc-text" x="205" y="340">>= 60 ?</text>
<text class="fc-mark" id="mark-d2" x="239" y="295"></text>
</g>
<!-- Yes2 -> Block C -->
<g class="fc-edge" id="e-d2-yes">
<path d="M285,330 L298,330"></path>
<polygon points="305,330 295,325 295,335"></polygon>
</g>
<text class="fc-text" x="291" y="320" font-size="10" fill="var(--ink-soft)">yes</text>
<g id="n-blockC">
<rect class="fc-shape fc-block" x="305" y="305" width="130" height="50" rx="8"></rect>
<text class="fc-text on-block" x="370" y="336">Grade C</text>
</g>
<!-- No2 -> Block F (else) -->
<g class="fc-edge" id="e-d2-no">
<path d="M205,385 L205,439"></path>
<polygon points="205,445 200,435 210,435"></polygon>
</g>
<text class="fc-text" x="221" y="415" font-size="10" fill="var(--ink-soft)">no</text>
<g id="n-blockF">
<rect class="fc-shape fc-block" x="130" y="450" width="150" height="50" rx="8"></rect>
<text class="fc-text on-block" x="205" y="476">Grade F</text>
<text class="fc-text" x="205" y="490" font-size="9" fill="var(--ink-soft)">(else)</text>
</g>
<!-- Block A -> down and around Block C -> left -> junction -->
<g class="fc-edge" id="e-blockA-merge">
<path d="M370,165 L370,180 L460,180 L460,560 L205,560"></path>
</g>
<!-- Block C -> down -> left -> junction -->
<g class="fc-edge" id="e-blockC-merge">
<path d="M370,355 L370,560 L205,560"></path>
</g>
<!-- Block F -> straight down to junction -->
<g class="fc-edge" id="e-blockF-merge">
<path d="M205,500 L205,560"></path>
</g>
<!-- Junction dot -->
<circle class="junction" id="junction" cx="205" cy="560" r="4.5"></circle>
<!-- Junction -> End -->
<g class="fc-edge" id="e-merge-end">
<path d="M205,560 L205,604"></path>
<polygon points="205,610 200,600 210,600"></polygon>
</g>
<!-- End -->
<g id="n-end">
<rect class="fc-shape fc-pill" x="135" y="610" width="140" height="42" rx="21"></rect>
<text class="fc-text on-pill" x="205" y="636">End</text>
</g>
</svg>
</div>
<p class="caption" id="caption"></p>
</div>
</div>
<script>
(function () {
const wrapper = document.currentScript.closest('.infographic-jsifei')
|| document.querySelector('.infographic-jsifei');
const bodyAttr = document.body.getAttribute('data-darkmode');
let dark;
if (bodyAttr === 'true') {
dark = true;
} else if (bodyAttr === 'false') {
dark = false;
} else {
const match = document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/);
dark = match ? match[1] === 'true' : false;
}
if (dark) wrapper.setAttribute('data-theme', 'dark');
const input = wrapper.querySelector('#scoreInput');
const caption = wrapper.querySelector('#caption');
const d1 = wrapper.querySelector('#n-d1 .fc-shape');
const d2 = wrapper.querySelector('#n-d2 .fc-shape');
const markD1 = wrapper.querySelector('#mark-d1');
const markD2 = wrapper.querySelector('#mark-d2');
const blockA = wrapper.querySelector('#n-blockA .fc-block');
const blockC = wrapper.querySelector('#n-blockC .fc-block');
const blockF = wrapper.querySelector('#n-blockF .fc-block');
const junction = wrapper.querySelector('#junction');
const eStartD1 = wrapper.querySelector('#e-start-d1');
const eD1Yes = wrapper.querySelector('#e-d1-yes');
const eD1No = wrapper.querySelector('#e-d1-no');
const eD2Yes = wrapper.querySelector('#e-d2-yes');
const eD2No = wrapper.querySelector('#e-d2-no');
const eAMerge = wrapper.querySelector('#e-blockA-merge');
const eCMerge = wrapper.querySelector('#e-blockC-merge');
const eFMerge = wrapper.querySelector('#e-blockF-merge');
const eMergeEnd = wrapper.querySelector('#e-merge-end');
const allEdges = [eStartD1, eD1Yes, eD1No, eD2Yes, eD2No, eAMerge, eCMerge, eFMerge, eMergeEnd];
function reset() {
d1.classList.remove('reached-yes', 'reached-no');
d2.classList.remove('reached-yes', 'reached-no');
markD1.textContent = ''; markD1.classList.remove('yes', 'no');
markD2.textContent = ''; markD2.classList.remove('yes', 'no');
[blockA, blockC, blockF].forEach(b => b.classList.remove('reached'));
junction.classList.remove('is-taken');
allEdges.forEach(e => e.classList.remove('is-check', 'is-taken'));
}
function update() {
reset();
const score = Number(input.value);
eStartD1.classList.add('is-check');
let grade;
if (score >= 90) {
d1.classList.add('reached-yes');
markD1.textContent = '✓'; markD1.classList.add('yes');
eD1Yes.classList.add('is-check');
blockA.classList.add('reached');
eAMerge.classList.add('is-taken');
grade = 'A';
} else {
d1.classList.add('reached-no');
markD1.textContent = '✗'; markD1.classList.add('no');
eD1No.classList.add('is-check');
if (score >= 60) {
d2.classList.add('reached-yes');
markD2.textContent = '✓'; markD2.classList.add('yes');
eD2Yes.classList.add('is-check');
blockC.classList.add('reached');
eCMerge.classList.add('is-taken');
grade = 'C';
} else {
d2.classList.add('reached-no');
markD2.textContent = '✗'; markD2.classList.add('no');
eD2No.classList.add('is-check');
blockF.classList.add('reached');
eFMerge.classList.add('is-taken');
grade = 'F';
}
}
eMergeEnd.classList.add('is-taken');
junction.classList.add('is-taken');
caption.innerHTML = `<strong>score = ${isNaN(score) ? '?' : score}</strong> → Grade ${grade}`;
}
input.addEventListener('input', update);
wrapper.querySelectorAll('.preset-btn').forEach(btn => {
btn.addEventListener('click', () => { input.value = btn.dataset.v; update(); });
});
update();
})();
</script>Only checked if the first
ifwas False.You can have multiple
elifblocks.If its condition is True, it runs Block B and skips the rest.
elif temperature > 20:
print("Nice weather!")🔸 else block:
Runs if none of the above conditions were True.
Acts as a “default”.
else:
print("It's cold!")🔁 Example Combined:
temperature = 25
if temperature > 30:
print("It's hot!") # Not printed
elif temperature > 20:
print("Nice weather!") # ✅ This is printed
else:
print("It's cold!")