-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass1.html
494 lines (444 loc) · 21.9 KB
/
class1.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Introduction to Python | Girl Develop It Ann Arbor</title>
<meta name="description" content="This is the official Girl Develop It Core Intro to Python course. The course is meant to be taught in four two-hour sessions. Each of the slides and practice files are customizable according to the needs of a given class or audience.">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/gdiaa.css" id="theme">
<link rel="stylesheet" href="lib/css/rainbow.css">
<link rel="stylesheet" href="css/print/pdf.css" media="print">
<script src="lib/js/head.min.js"></script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!-- INTRO -->
<section>
<!-- Opening slide -->
<section>
<img src="images/gdi_logo_badge.png" class="img--bare" height="450px" />
<div class="box--small">
<h3><span class="green">Intro to Python</span><br/><small><span class="blue">Class 1</span></small></h3>
<p><small>@gdiannarbor | #GDIA2 | #IntroToPython</small></p>
</div>
</section>
<section>
<h3>What we will cover today</h3>
<ul class="list--xtall box--small copy--small">
<li class ="fragment">Why Python?</li>
<li class ="fragment">What is programming?</li>
<li class ="fragment">Variables and arithmetic</li>
<li class ="fragment">Statements and Error Messages</li>
<li class ="fragment">Development Environment Setup</li>
</ul>
</section>
<section>
<h3>Scary things we'll be facing</h3>
<ul class="list--xtall box--small copy--small">
<li class="fragment">Command line</li>
<li class="fragment">Writing code</li>
<li class="fragment">Learning new things</li>
<li class="fragment">Code that won't run</li>
<li class="fragment">Code not working</li>
<li class="fragment">Asking questions in a room full of people</li>
<li class="fragment">Asking "experts" beginner questions</li>
<li class="fragment">Not getting it</li>
</ul>
</section>
</section>
<!-- WHAT IS PYTHON : 25 minutes -->
<section>
<section>
<h3>Why Python?</h3>
<ul class="list--tall copy--small box--small">
<li class ="fragment">Suitable for beginners, yet used by professionals</li>
<li class ="fragment">Readable, maintainable code</li>
<li class ="fragment">Rapid rate of development</li>
<li class ="fragment">Few "magical" side-effects</li>
<li class ="fragment">Variety of applications</li>
</ul>
</section>
<section>
<h3>What is Python used for?</h3>
<ul class="list--tall copy--small box--small">
<li class ="fragment">System Administration (Fabric, Salt, Ansible)</li>
<li class ="fragment">3D animation and image editing (Maya, Blender, Gimp)</li>
<li class ="fragment">Scientific computing (numpy, scipy)</li>
<li class ="fragment">Web development (Django, Flask)</li>
<li class ="fragment">Game Development (Civilization 4, EVE Online)</li>
</ul>
</section>
<section>
<h3>Who is using Python?</h3>
<ul class="list--tall copy--small box--small">
<li>Disney</li>
<li>Dropbox</li>
<li>Canonical and Red Hat</li>
<li>Google</li>
<li>NASA</li>
</ul>
</section>
</section>
<!-- WHAT IS PROGRAMMING -->
<section>
<section>
<h3>What is programming?</h3>
<ul class="list--xtall box--small copy--small">
<li class="fragment">Teaching the computer to do a task</li>
<li class="fragment">A program is made of one or more files of code, each of which solve part of the overall task.</li>
<li class="fragment">The code that you program is human readable but also needs to exist in a form that the computer can run directly. This form is not human readable.</li>
<li class="fragment">Don't focus on what's "under the hood" for now. We will "drive the car" first.</li>
<li class="fragment">In other words, there are many layers to the onion. We start at one layer and slowly move toward layers that are beneath or above us.</li>
</ul>
</section>
<section>
<h4>Command line, Python Shell, Text Editors</h4>
<table class="copy--small box">
<tr>
<td style="width: 200px;"><strong>Terminal</strong></td>
<td style="padding-bottom: 20px;">A program that has a <span class="blue">command line interface</span> and <span class="green">issues commands to the operating system</span>.</td>
</tr>
<tr>
<td><strong>Python Shell</strong></td>
<td style="padding-bottom: 20px;">A <span class="blue">command line program</span> that runs inside of the terminal, <span class="green">takes Python code</span> as input, interprets it, and prints out any results.</td>
</tr>
<tr>
<td><strong>Text Editor</strong></td>
<td style="padding-bottom: 20px;">A <span class="blue">program that opens text files</span> and allows the user to edit and save them. (Different than a word processor).</td>
</tr>
</table>
</section>
<section>
<h3>Example Text Editors</h3>
<table class="copy--small" style="width: auto; margin: 2em auto;">
<tr>
<td style="width: 200px;"><strong>Linux</strong></td>
<td style="padding-bottom: 20px;">Gedit, Jedit, Kate</td>
</tr>
<tr>
<td><strong>MacOSX</strong></td>
<td style="padding-bottom: 20px;">TextMate, TextWrangler</td>
</tr>
<tr>
<td><strong>Windows</strong></td>
<td style="padding-bottom: 20px;">Notepad++</td>
</tr>
<tr>
<td><strong>All</strong></td>
<td style="padding-bottom: 20px;">Sublime Text, Vim, Emacs</td>
</tr>
</table>
</section>
</section>
<!-- Let's develop it: 10 minutes-->
<!-- <section>
<h3>Let's Develop It!</h3>
<p class="box--small copy--small">Let's setup our computer for Python programming</p>
<ul class="list--xtall box--small copy--small">
<li>
<a href="http://www.sublimetext.com/3" target="_blank">Install Sublime Text 3</a> - A text editor
</li>
<li>
<a href="http://www.python.org/download/" target="_blank">Install Python 3</a>
</li>
<li>
<strong>Windows Users:</strong> After installing Python, open the "powershell" program and type:
<br/><code class="copy--xsmall">[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python35", "User")</code>
</li>
<li>
Locate and run the terminal program. Type <code>python3</code> and hit enter.
</li>
<li>
More setup instructions are available:
<a href="http://learnpythonthehardway.org/book/ex0.html" target="_blank">here</a>
<br/><small>(Unlike these instructions, install Python 3, not Python 2. You can, but don't have to install the other text editors recommended in this guide)</small>
</li>
</ul>
</section> -->
<!-- Block 2: 30 minutes -->
<section>
<h3>Let's Develop It!<br/><small><span class="blue">Working in the Python Shell</span></small></h3>
<p class="box--small">Open up your terminal and type <code>python3</code></p>
<p class="fragment copy--small box--small">Follow along with the examples in the upcoming slides.<br/><strong>Just type them right in!</strong></p>
<p class="fragment copy--small box--small">Feel free to explore, as well.<br/>You will not accidentally break things!</p>
<p class="fragment box--small copy--xsmall">When you're done, type <code>exit()</code> to close the Python shell</p>
</section>
<!-- Variables & Arithmatic -->
<section>
<section>
<h3>Variables and Arithmetic</h3>
<div class='box--small'><pre><code contenteditable class="python" style="min-height: 50px;">
3 + 4
2 * 4
6 - 2
4 / 2
</code></pre></div>
<div class='box--small'><pre><code contenteditable class="python" style="min-height: 50px;">
a = 2
b = 3
print(a + b)
c = a + b
print(c * 2)
</code></pre></div>
<div class='box--small'><pre><code contenteditable class="python" style="min-height: 50px;">
a = 0
a = a + .5
print(a)
</code></pre></div>
</section>
<section>
<h3>Strings</h3>
<div class="box--small"><pre><code contenteditable class="python" style="min-height: 50px;">
a = 'Hello '
b = 'World'
c = a + b
print(c)
</code></pre></div>
<div class="box--small"><pre><code contenteditable class="python" style="min-height: 50px;">
a = "Spam "
b = a * 4
print(b)
</code></pre></div>
<div class="box--small"><pre><code contenteditable class="python" style="min-height: 50px;">
a = 'spam '
b = 'eggs'
c = a * 4 + b
print(c)
</code></pre></div>
</section>
<section>
<h3>Data Types</h3>
<ul class="list--tall copy--small box--small">
<li>Variables are used to store data</li>
<li class="fragment">Among other things, variables are used to represent something that can't be known until the program is run</li>
<li class="fragment">Data always has a "type"</li>
<li class="fragment">The type of a piece of data helps define what it can do</li>
<li class="fragment">The type can be found using: <code>type()</code></li>
<li class="fragment"><code>type()</code> is a <strong>function</strong>. We <em>call</em> it by using parenthesis and pass it an object by placing the object inside the parenthesis
<pre><code contenteditable class="python" style="min-height: 50px;">
a = 4
print(type(a))
print(type(4))
print(type(3.14))
b = 'spam, again'
print(type(b))
print(type("But I don't like spam"))
</code></pre>
</li>
</ul>
</section>
<section>
<h3>Data types - continued ...</h3>
<ul class="list--tall copy--small box--small">
<li>Data values can be used with a set of <strong>operators</strong></li>
<li>An "int" or "float" can be used with any of: <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code></li>
<li>A "string" can be used with any of: <code>+</code>, <code>*</code></li>
<li>What happens if we try to use division or subtraction with a string?</li>
</ul>
<pre><code contenteditable class="python" style="min-height: 50px;">
print("Spam" - "am")
a = 'Spam and eggs'
print(a / 'hashbrowns')
print(a / 6)
</code></pre>
</section>
</section>
<!-- STATEMENTS & ERRORS -->
<section>
<section>
<h3>Errors</h3>
<ul class="list--tall copy--small box--small">
<li class="fragment">There are different kinds of errors that can occur.<br/><small>We've seen a few already.</small></li>
<li class="fragment">A "runtime error" results in an <strong>Exception</strong>, which has several types.<br/><small>Each type gives us some information about the nature of the error and how to correct it</small></li>
<li class="fragment">One type of exception is a <strong>SyntaxError</strong>. This results when our <span class="red">code can not be evaluated because it is incorrect</span> at a syntactic level.<br/><small>In other words, we are not following the "rules" of the language.</small></li>
<li class="fragment">Some other examples are the <strong>TypeError</strong> and <strong>NameError</strong> exceptions.</li>
</ul>
</section>
<section>
<h3>Errors - continued ...</h3>
<div class="box--small"><pre><code contenteditable class="python">
# SyntaxError - Doesn't conform to the rules of Python.
# This statement isn't meaningful to the computer
4spam)eggs(garbage) + 10
# NameError - Using a name that hasn't been defined yet
a = 5
print(d)
d = 10
# TypeError - Using an object in a way that its type does not support
'string1' - 'string2'
</code></pre></div>
<p class="copy--small">There are also <strong>semantic</strong> errors.<br/><small>These are harder to catch because the computer can't catch them for us.</small></p>
</section>
</section>
<!-- Let's develop it: 10 minutes -->
<section>
<h3>Let's Develop It</h3>
<p class="box copy--small">We'll practice what we've learned in the shell.</p>
<p class="box copy--small">Review the slides on your computer and practice entering any commands you didn't fully understand before.</p>
<p class="box copy--small">Ask the teacher, TAs, and students around you for help!</p>
</section>
<!-- DEV ENV SETUP : 30 Minutes -->
<section>
<section>
<h3>Using the Terminal (OSX) or PowerShell (Windows)</h3>
<p class="copy--small box--small">Try each of the following commands in turn:</p>
<table class="copy--xsmall" style='line-height: 1.5'>
<tr>
<th style="width: 160px;"><strong>Command</strong></th>
<th style="width: 280px;"><strong>Short for</strong></th>
<th style="padding-bottom: 20px"><strong>Description</strong></th>
</tr>
<tr>
<td><code>pwd</code></td>
<td>Print working directory</td>
<td style="padding-bottom: 20px">Displays what folder you are in.</td>
</tr>
<tr>
<td><code>ls</code></td>
<td>List</td>
<td style="padding-bottom: 20px">Lists the files and folders in the current folder</td>
</tr>
<tr>
<td><code>cd</code></td>
<td>Change directory</td>
<td style="padding-bottom: 20px">Change to another folder. Takes the folder name as an argument. 'cd ..' goes up a directory</td>
</tr>
<tr>
<td><code>cat</code></td>
<td>Concatenate</td>
<td style="padding-bottom: 20px">Prints the contents of a file. Takes a filename as an argument</td>
</tr>
</table>
</section>
<section>
<h3>Creating a folder</h3>
<p class="copy--small box">We need a folder to save our work in.</p>
<div class="fragment">
<p class=" copy--xsmall">The <code>-></code>'s below indicate the expected output of the previous command.</p>
<pre><code contenteditable class=" bash small">
pwd
-> /home/username
mkdir Projects
cd Projects
mkdir gdi-intro-python
cd gdi-intro-python
pwd
-> /home/username/Projects/gdi-intro-python
</code></pre>
<p class="copy--xsmall box--small">Now that the folders are made, we only have to use<br/><code>cd Projects/gdi-intro-python</code> in the future.</p>
</div>
</section>
<section>
<h3>The Text Editor</h3>
<p class="copy--small box--small">Open sublime text.</p>
<ul class="list--tall copy--small box--small">
<li class="fragment">Click "File", then "Open". Navigate to the <code>gdi-intro-python</code> <strong>folder</strong> we just created and click "Open"</li>
<li class="fragment">In the text editor, enter the following:
<pre><code contenteditable class="python" style="min-height: 50px;">
print('I am a Python program!')
</code></pre>
</li>
<li class="fragment">Click "File", then "Save As...". Type "class1.py" and click "Save".</li>
<li class="fragment">Open a terminal and navigate to the <code>gdi-intro-python</code> folder.<br/><small>If you don't already have this folder open in a terminal.</small></li>
<li class="fragment">Type <code>python3 class1.py</code></li>
<li class="fragment">You should see the terminal print "I am a Python program!"</li>
</ul>
</section>
<section>
<h3>User Input</h3>
<p class="copy--small box--small">To obtain user input, use <code>input()</code></p>
<p class="copy--small box--small">Change the class1.py text to the following and run it again</p>
<pre><code contenteditable class="python" style="min-height: 50px;">
input_value = input("Enter a radius:")
radius = float(input_value)
area = 3.14159 * radius * radius
print("The area of a circle with radius " + input_value + " is:")
print(area)
</code></pre>
<p class="copy--small box--small">The user's input is a string, so we use <code>float()</code> to make it a number</p>
</section>
</section>
<!-- Let's develop it: 15 minutes -->
<section>
<h3>Let's Develop It!</h3>
<p class="copy--small box">Write your own program that uses input<br/>and does something else with the value</p>
<p class="copy--xsmall box">You can use float() to treat the input as a number if you need a number,<br/>or use the input directly as a string.</p>
</section>
<!-- OUTRO -->
<section>
<section>
<h3>Questions?</h3>
</section>
<section>
<h3>Homework</h3>
<p class="copy--small box">Write a program that could replace the initial conversation you have at the checkout line. It should do the following:</p>
<div class='box--small'>
<pre><code contenteditable class="python" style="min-height: 50px;">
>> Did you find everything ok?
(wait for input)
>> What's your name?
(read in a name from the user)
>> Hi, (User's Name) do you want paper or plastic?
(wait for input)
>> What is your total before tax?
(read in a total)
>> Your total with sales tax is: (total with sales tax)
(wait for input before exiting)
</code></pre></div>
</section>
<section>
<h3>Want help?</h3>
<div class="box">
<p class="box"><a href="https://gdiaa.slack.com/messages/0516-intro-python/details/" target="_blank" class="roll"><span>#0516-intro-python</span></a></p>
<p><small>Not on Slack? <a target="_blank" href="http://bit.ly/gdiaa-slack" class="roll"><span data-title="bit.ly/gdiaa-slack">bit.ly/gdiaa-slack</span></a></small></p>
</div>
</section>
<section>
<img src="images/gdi_logo_badge.png" class="img--bare" height="450px" />
<div class="box--small">
<h3><span class="green">Intro to Python</span><br/><small><a href="class2.html">Class 2 »</a></small></h3>
<p><small>@gdiannarbor | #GDIA2 | #IntroToPython</small></p>
</div>
</section>
</section>
</div>
<footer>
<div class="copyright">
@gdiannarbor | #GDIA2 | #IntroToPython
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png" /></a>
</div>
</footer>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
rollingLinks: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>