-
Notifications
You must be signed in to change notification settings - Fork 3
/
lesson4.html
executable file
·158 lines (142 loc) · 5.44 KB
/
lesson4.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
<!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 4 - Loops</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 4:<br>Loops</h3>
<p>
<small>Expedia Code Academy</small>
<br>
<img src="static/img/code_academy_logo.png" border="0px">
</p>
</section>
<section>
<h3>For loops</h3>
For loops are a way to loop (or "iterate") through a list.
<pre><code class="python" data-trim>
expedia_brands = ['Hotels.com', 'EPS', 'Expedia']
for brand in expedia_brands:
print('I love ' + brand)
for scoobydoo in expedia_brands: # same as the above for loop
print('I love ' + scoobydoo)
</code></pre>
<p class="fragment">
The <span id="code">word</span> variable is recreated every round of the loop, with the value of the next item in the list.
</p>
<p class="fragment">
You can name it anything you like! Just use the same variable name within the for loop.
</p>
</section>
<section>
<h3>Strings can be treated like lists</h3>
<div>
<p>
What do we think this code will do?<br>
</p>
<pre><code class="python" data-trim>
my_string = 'Today is a great day!'
print(my_string[0])
</code></pre>
</div>
<div class="fragment">
<p>
Strings are simply lists of characters!<br>
<pre><code class="python" data-trim>
total = 0
my_string = 'Today is a great day!'
for letter in my_string:
???
</code></pre>
(⭐️) 4c. Count the number of 'a's in my_string.
</p>
</div>
</section>
<section>
<h3>While or for loops?</h3>
<p>
While loops are useful when you want something to loop forever, or <u>until</u> something changes!
<br><br>
</p>
<p class="fragment">
For loops are useful when you <u>have your data already</u> and want to loop through it until it ends.
<br><br>
</p>
<p class="fragment">
<b>What about these examples?</b>
<small>
<ul>
<li class="fragment">You want to ask for user input() until they type the string 'EXIT'.</li>
<li class="fragment">You have a list of exam marks, and want to see how many are above a pass mark.</li>
<li class="fragment">You want to process a list of numbers until you encounter a negative number</li>
</ul>
</small>
</p>
</section>
<section>
<h3>Exercises</h3>
<pre><code class="python" data-trim>
some_numbers = [1.5, 37.2, 55, -1.94]
</code></pre>
<ul>
<li>
(⭐) 4d. Using <span id="code">some_numbers</span>, print each element multiplied by 10.
<br>
Example output: 15.0, 372.0, 550, -19.4
<br><br>
</li>
<li>
(⭐⭐) 4e. Count how many words in a given list are longer than 3 letters. See
<a href="https://github.com/python101ldn/exercises/blob/master/Session_4/4e_letter_counter.py" target="_blank">
here
</a>
for a list of words to use.
</a>
</li><br>
</ul>
</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>