-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlesson1.html
More file actions
executable file
·269 lines (247 loc) · 10.8 KB
/
lesson1.html
File metadata and controls
executable file
·269 lines (247 loc) · 10.8 KB
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
267
268
269
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Week 1 - Introduction to Python</title>
<link rel="stylesheet" href="reveal/css/reveal.css">
<!-- Theme set to Simple Serif with custom overrides below -->
<link rel="stylesheet" href="reveal/css/theme/simple.css">
<link rel="stylesheet" href="static/css/custom.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="reveal/lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'reveal/css/print/pdf.css' : 'reveal/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<!-- TITLE SLIDE -->
<section>
<br>
<h2>Python 101</h2>
<h3>Week 1:<br>Introduction to Python</h3>
<p>
<small>Expedia Code Academy</small>
<br>
<img src="static/img/code_academy_logo.png" border="0px">
</p>
</section>
<section>
<h3>What is our mission?</h3>
<p class="fragment">
<br>Simply put, to get you coding!<br><br>
</p>
<span class="fragment">
By the end of this course, you'll be able to:<br>
</span>
<ul>
<li class="fragment">Understand how code works</li>
<li class="fragment">Write basic Python code</li>
<li class="fragment">Design larger programs that combine various programming concepts learned</li>
</ul>
</section>
<section>
<h3>Class Resources</h3>
<span class="fragment">
There are a number of resources that we use in this class:<br><br>
</span>
<ul>
<li class="fragment">The lesson slides are found <a href="https://python101ldn.github.io/" target="_blank">
here
</a></li>
<li class="fragment">Exercises and solutions are found <a href="https://github.com/python101ldn/exercises" target="_blank">
here
</a></li>
<li class="fragment">Slack room for the class</li>
</ul>
</section>
<section>
<h3>Why Python?</h3>
<p>
It's used by a lot of companies<br>
<img src="https://instagram-brand.com/wp-content/uploads/2016/11/app-icon2.png" height="120px">
<img src="http://www.stickpng.com/assets/images/580b57fcd9996e24bc43c529.png" height="120px">
<img src="./static/img/google_logo.png" height="120px">
<br>
It has many use cases and it's fun to program in!!<br>
<ul>
<li>Process a file</li>
<li>Build a website</li>
<li>Create a game</li>
<li>Or anything else you can think of, really!</li>
</ul>
</p>
</section>
<section>
<h3>Installation</h3>
<br>
<p>Please check out <a href="https://python101ldn.github.io/setup" target="_blank">the guide!</a></p>
</section>
<section>
<h3>Variables</h3>
<p>
<b></b>Variables are containers for your data</b><br><br>
The name of the variable is chosen by the software developer (that’s you!)<br><br>
<div style="margin:auto;width:500px;height:100px;border:1px solid #000;">my_name = 'Monty'</div>
<br>
<div style="margin:auto;width:500px;height:100px;border:1px solid #000;">my_age = 100</div>
</p>
</section>
<section>
<h3>Variables</h3>
<br>
<p>
Go to <a href="http://pythontutor.com/" target="_blank">pythontutor.com</a> to test out this code:
<br><br>
<pre><code class="python" data-trim>
my_name = 'Monty'
my_age = 100
</code></pre>
<br>
Try the <a href="http://pythontutor.com/visualize.html#mode=edit" target="_blank">Visualize Execution</a> mode to step through your program.
</p>
</section>
<section>
<h3>Variables</h3>
<div>
<p>We can also change what is inside an existing variable:<br></p>
<pre><code class="python" data-trim>
my_name = 'Montgomery'
print(my_name)
</code></pre>
What do you think will be printed?<br><br>
</div>
<div class="fragment">
<p>Will the following lines of code work? Why/why not?<br></p>
<pre><code class="python" data-trim>
my_Name = 'John Cleese'
my age = 999
</code></pre>
</div>
</section>
<section>
<h3>Numbers</h3>
<p>
Python can do basic maths with pretty big (or small) numbers!<br><br>
You can do the usual operations on these numbers:
<ul>
<li>Addition e.g. <span id="code">38 + 138</span></li>
<li>Subtraction e.g. <span id="code">500 - 2222</span></li>
<li>Multiplication e.g. <span id="code">33 * 55</span></li>
<li>Division e.g. <span id="code">400 / 3</span></li>
</section>
<section>
<h3>(⭐) 1a. Magic number trick</h3>
<p>
<small>
<ul>
<li class="fragment">Create a variable called <span id="code" style="color:red;">start_number</span>, and make it a random number</li>
<li class="fragment">Create a variable called <span id="code" style="color:blue;">step_1</span>, and make it <span id="code" style="color:red;">start_number</span> multiplied by 2</li>
<li class="fragment">Create a variable called <span id="code" style="color:orange;">step_2</span>, and add 9 to <span id="code" style="color:blue;">step_1</span></li>
<li class="fragment">Create a variable called <span id="code" style="color:green;">step_3</span>, and subtract 3 from <span id="code" style="color:orange;">step_2</span></li>
<li class="fragment">Create a variable called <span id="code" style="color:purple;">step_4</span>, and divide <span id="code" style="color:green;">step_3</span> by 2</li>
<li class="fragment">Create a variable called <span id="code" style="color:magenta;">result</span>, and subtract <span id="code" style="color:red;">start_number</span> from <span id="code" style="color:purple;">step_4</span></li>
<li class="fragment">Print <span id="code" style="color:magenta;">result</span></li>
</ul>
</small>
</p>
</section>
<section>
<h3>How does Python work?</h3>
<p>
<pre><code class="python" data-trim>
print(calculation) # This will produce an error!
calculation = 55 + 55
print(calculation) # prints 110
calculation = 55 * 55
print(calculation) # prints 3025
</code></pre>
<ul>
<li>Python evaluates files from top to bottom</li>
<li>Variable values are updated as it goes</li>
<li><span id="code">print</span> is a function that prints whatever value you give it in brackets</li>
</ul>
</p>
</section>
<section>
<h3>Strings</h3>
<p>
Strings are bits of text with apostrophes e.g.<br><span id="code">'I am a String, with 34 characters!'</span><br><br>
They can include letters, numbers and symbols - all of these are treated as text only, with no special value!<br><br>
What do you think this line of code will do?
<pre><code class="python" data-trim>
mystery = '1' + '2'
print(mystery)
</code></pre>
</section>
<section>
<h3>Strings</h3>
Adding Strings together is called <em>concatenation</em><br><br>
It can be really useful!
<pre><code class="python" data-trim>
first = 'Harry'
last = 'Potter'
sentence = 'Welcome to Hogwarts, ' + first + ' ' + last + '!'
print(sentence)
</code></pre><br>
How would we concatenate (add together) the <span id="code">first</span> and <span id="code">last</span> to make a variable called <span id="code">full_name</span>?
</section>
<section>
<h3>Accepting user input</h3>
What if we could provide data while our code is running?
<p class="fragment">
The <span id="code">input</span> function pauses the program until the user types something and presses Enter.
</p>
<p class="fragment">
We can then use what the user typed as a variable in the code!
</p>
<div class="fragment">
<pre><code class="python" data-trim>
users_name = input('What is your name? ')
print('Hello, ' + users_name + '!')
</code></pre>
(⭐⭐️) 1b. Ask the user to enter their first and last names, then welcome them to Hogwarts!
</div>
</section>
<section>
<h3>Appendix: More about print</h3>
<br>
You can supply multiple <i>arguments</i> to the print function and it will concatenate them together with a space between each one.
<br><br>
<pre><code class="python" data-trim>
first = 'Harry'
last = 'Potter'
greeting = 'Welcome to Hogwarts,'
print(greeting, first, last)
</code></pre><br>
</section>
</div>
</div>
<script src="reveal/lib/js/head.min.js"></script>
<script src="reveal/js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
dependencies: [
{ src: 'reveal/plugin/markdown/marked.js' },
{ src: 'reveal/plugin/markdown/markdown.js' },
{ src: 'reveal/plugin/notes/notes.js', async: true },
{ src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
],
history: true,
progress: false,
center: false, // disable vertical centering of text
transition: 'none'
});
</script>
</body>
</html>