-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.html
executable file
·266 lines (254 loc) · 10.1 KB
/
variables.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
263
264
265
266
<!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>Variable 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="index.html">⬅️</a></span>
Variable practice
<span><a href="selection.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="data-types">
Data Types
</button>
<button class="tab-button" data-tab="input">Input</button>
<button class="tab-button" data-tab="casting">Casting</button>
<button class="tab-button" data-tab="math-operators">
Math Operators
</button>
<button class="tab-button" data-tab="updating-variables">
Updating Variables
</button>
<button class="tab-button" data-tab="together">
Putting It All Together
</button>
</div>
<div class="tab-content active" id="intro">
<h1>Variables and Data Types in Python</h1>
<p>
Welcome to the exciting world of variables! In Python, variables
are like magical containers that can hold different types of
information. Let's explore some of the most common ones.
</p>
</div>
<div class="tab-content" id="data-types">
<h2>Data Types: Different Flavours of Information</h2>
<p>
Just like ice cream comes in different flavours, data in Python
comes in different types:
</p>
<table class="summary-table">
<thead>
<tr>
<th>Data types</th>
<th>Meaning</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Strings</td>
<td>Alphanumeric characters - text wrapped in quotes</td>
<td><code>"Hello, Python!"</code></td>
</tr>
<tr>
<td>Integers</td>
<td>Whole numbers</td>
<td><code>42</code> or <code>-10</code></td>
</tr>
<tr>
<td>Floats</td>
<td>Numbers with decimal points</td>
<td><code>3.14</code> or <code>-0.5</code></td>
</tr>
</tbody>
</table>
</div>
<div class="tab-content" id="input">
<h2>Input: Getting Information from Users</h2>
<p>
Remember the <code>input()</code> function? It's super helpful,
but it has a secret: it always gives us a string, even if the
user types a number!
</p>
<div class="codeExample">
<code>age = input("How old are you? ")</code>
</div>
<p>
If the user enters 12, the variable <code>age</code> will be the
string <code>"12"</code>, not the integer <code>12</code>.
</p>
</div>
<div class="tab-content" id="casting">
<h2>Casting: Changing Data Types</h2>
<p>
Sometimes we need to change the type of our data. We can do this
with casting:
</p>
<div class="codeExample">
<code>age = int(input("How old are you? "))</code>
</div>
<p>
Now if the user enters 12, the variable <code>age</code> will be
the integer <code>12</code>, which we can use in maths!
</p>
</div>
<div class="tab-content" id="math-operators">
<h2>Mathematical Operators: Doing Maths with Python</h2>
<p>
Python is great at maths! Here are some operators you can use:
</p>
<table class="summary-table">
<thead>
<tr>
<th>Operator</th>
<th>Function</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>+</code></td>
<td>addition</td>
</tr>
<tr>
<td><code>-</code></td>
<td>subtraction</td>
</tr>
<tr>
<td><code>*</code></td>
<td>multiplication</td>
</tr>
<tr>
<td><code>/</code></td>
<td>division</td>
</tr>
</tbody>
</table>
</div>
<div class="tab-content" id="updating-variables">
<h2>Updating Variables: Changing Values</h2>
<p>
Variables are not only for storing values - we can also change
them as our program runs. This is super useful for keeping track
of things that change, like scores in a game!
</p>
<p>Here's how we can update a variable:</p>
<div class="codeExample">
<code>
num = 4<br />
print("num starts as:", num)<br />
num = num + 2<br />
print("After adding 2, num is now:", num)
</code>
</div>
<p>
In this example, <code>num</code> starts as 4. Then we add 2 to
it and store the result back in <code>num</code>. So
<code>num</code> becomes 6!
</p>
<p>
We can do this with any mathematical operation. Here are a few
more examples:
</p>
<div class="codeExample">
<code>
num = num * 3 # Multiplies num by 3 <br />
num = num - 1 # Subtracts 1 from num <br />
num = num / 2 # Divides num by 2 <br />
</code>
</div>
<p>
This is really powerful because it lets our variables change and
grow as our program runs. Try using this in your next program!
</p>
</div>
<div class="tab-content" id="together">
<h2>Putting It All Together</h2>
<p>Let's use everything we've learned to make a cool program:</p>
<div class="codeExample">
<code>
days = int(input("Give me a number of days: ")) <br />
hours = days * 24 <br />
print("There are", hours, "hours in", days, "days") <br />
</code>
</div>
<p>
This program asks for a number of days, casts the response to an
integer, calculates the number of hours, and then prints the
result.
</p>
<p>
Now it's your turn! Can you make a program that asks for
someone's age and then calculates how many months they've been
alive? (Hint: multiply their age by 12!) 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/baseImage.webp" alt="" />
<p id="exampleQuestion"></p>
<p id="exampleAnswer"></p>
<p id="exampleResponse"></p>
</section>
<section class="cartoon2">
<img id="questionImage" src="img/baseImageTwoQs.webp" alt="" />
<p id="exampleQuestion1"></p>
<p id="exampleQuestion2"></p>
<p id="exampleAnswer1"></p>
<p id="exampleAnswer2"></p>
<p id="exampleResponse2"></p>
</section>
<section class="code hidden">
<button id="copyMe" class="btn small-btn" pre="Click to copy code">
📋
</button>
<p id="codeQuestion1"></p>
<p id="codeQuestion2"></p>
<p id="codeCalculation"></p>
<p id="response"></p>
</section>
</section>
</main>
<button id="forceSpongebob" class="btn small-btn" pre="Spongebob">
🧽
</button>
</div>
<script type="module" src="js/variables.js"></script>
</body>
</html>