-
Notifications
You must be signed in to change notification settings - Fork 0
/
selection.html
262 lines (249 loc) · 9.67 KB
/
selection.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="Variable practice questions" />
<meta name="keywords" content="one, two, three" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet"
/>
<title>Selection practice questions</title>
<!-- external CSS link -->
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div>
<header>
<h1>Programming practice</h1>
</header>
<main>
<h2>
<span><a href="variables.html">⬅️</a></span>
Selection practice with if/else
<span><a href="iterationWhile.html">➡️</a></span>
</h2>
<nav>
<a href="#" class="btn" id="background">Background</a>
<a href="#" class="btn" id="inspire">Inspire me!</a>
<a href="#" class="btn" id="help">Help me!</a>
</nav>
<section class="background hidden">
<div class="tab-container">
<div class="tab-buttons">
<button class="tab-button active" data-tab="intro">
Introduction
</button>
<button class="tab-button" data-tab="programming-constructs">
Programming Constructs
</button>
<button class="tab-button" data-tab="if-else">
If-Else Statements
</button>
<button class="tab-button" data-tab="equals-signs">
Equals Signs
</button>
<button class="tab-button" data-tab="indentation">
Indentation
</button>
<button class="tab-button" data-tab="example">
Putting It All Together
</button>
</div>
<div class="tab-content active" id="intro">
<h1>Selection in Python</h1>
<p>
Welcome to the world of decision-making in programming! Today,
we're going to learn about selection, which is like teaching
your computer to make choices. It's a bit like being the
director of your own interactive movie!
</p>
</div>
<div class="tab-content" id="programming-constructs">
<h2>The Three Musketeers of Programming</h2>
<p>
In programming, we have three main ways to control how our code
runs. These are called programming constructs:
</p>
<table class="summary-table">
<thead>
<tr>
<th>Construct</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>sequence</td>
<td>
This is like following a recipe step by step and in order.
</td>
</tr>
<tr>
<td>selection</td>
<td>
This is about making choices, today's task, uses if, elif,
else.
</td>
</tr>
<tr>
<td>iteration</td>
<td>
This is about repeating things, but that's a story for
another day.
</td>
</tr>
</tbody>
</table>
<p>
Today, we're focusing on selection, which is all about making
decisions in our code.
</p>
</div>
<div class="tab-content" id="if-else">
<h2>If-Else: Teaching Your Computer to Make Choices</h2>
<p>
In Python, we use 'if' and 'else' statements to make decisions.
It's like asking a question and doing different things based on
the answer.
</p>
<div class="codeExample">
<code>
if it_is_raining:<br />
<span class="tab"></span>print("Take an umbrella")<br />
else:<br />
<span class="tab"></span>print("Enjoy the sunshine")<br />
</code>
</div>
<p>
In this example, if it's raining, the program tells you to take
an umbrella. Otherwise (else), it tells you to enjoy the
sunshine.
</p>
</div>
<div class="tab-content" id="equals-signs">
<h2>The Tale of Two Equals: = vs ==</h2>
<p>In Python, we use equals signs in two different ways:</p>
<table class="summary-table">
<thead>
<tr>
<th>Operator</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>=</code></td>
<td>
This is for assigning values to variables. It's like
putting something in a box.
</td>
</tr>
<tr>
<td><code>==</code></td>
<td>
This is for comparing values. It's like asking "Are these
the same?"
</td>
</tr>
</tbody>
</table>
<div class="codeExample">
<code>
favourite_colour = "blue" # Assigning a value<br />
if favourite_colour == "blue": # Comparing values<br />
<span class="tab"></span>print("Great choice!")<br />
</code>
</div>
</div>
<div class="tab-content" id="indentation">
<h2>The Importance of Indentation</h2>
<p>
In Python, indentation (the space at the beginning of a line) is
super important! It tells Python which lines of code belong to
an if statement.
</p>
<p>After an if or else statement, you need to:</p>
<ol>
<li>Put a colon (:) at the end of the line</li>
<li>
Indent the next line (usually by pressing the Tab key once)
</li>
</ol>
<div class="codeExample">
<code>
if score > 10:<br />
<span class="tab"></span>print("You win!") # This line is
indented<br />
<span class="tab"></span>print("Well done!") # This line is
also indented<br />
print("Game over") # This line is not indented, so it's not
part of the if<br />
</code>
</div>
</div>
<div class="tab-content" id="example">
<h2>Putting It All Together</h2>
<p>Let's use everything we've learned to make a fun program:</p>
<div class="codeExample">
<code>
correct_answer = "spongebob squarepants"<br />
best_show = input("What is the best TV show? ")<br />
if best_show == correct_answer:<br />
<span class="tab"></span>print("Absolutely!", correct_answer,
"is glorious")<br />
else:<br />
<span class="tab"></span>print(best_show, "?!?! No way - it
is", correct_answer)<br />
</code>
</div>
<p>
This program asks for your favourite TV show. If you say
"spongebob squarepants", it agrees with you. If you say anything
else, it tells you that Spongebob is actually the best!
</p>
<p>
Now it's your turn! Can you make a program that asks for a
password and only lets the user in if they enter the correct
one? Press inspire me for more ideas of what to code.
</p>
</div>
</div>
</section>
<section class="example hidden">
<h3>
Write a program to...
<span id="topic"></span>
</h3>
<section class="cartoon1">
<img id="questionImage" src="img/baseImageSelection.webp" alt="" />
<p id="selectionQuestion"></p>
<p id="selectionAnswer1"></p>
<p id="ifReply"></p>
<p id="selectionAnswer2"></p>
<p id="elseReply"></p>
</section>
<section class="code hidden">
<button id="copyMe" class="btn small-btn" pre="Click to copy code">
📋
</button>
<p id="codeCorrectAnswer"></p>
<p id="codeQuestion"></p>
<p id="codeIfCheck"></p>
<p id="codeIfReply"></p>
<p id="codeElse">else:</p>
<p id="codeElseReply"></p>
<p id="response"></p>
</section>
</section>
</main>
<button id="forceSpongebob" class="btn small-btn" pre="Spongebob">
🧽
</button>
</div>
<script type="module" src="js/selection.js"></script>
</body>
</html>