-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlesson7.html
More file actions
executable file
·154 lines (134 loc) · 5.17 KB
/
lesson7.html
File metadata and controls
executable file
·154 lines (134 loc) · 5.17 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
<!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 7 - Functions</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 7:<br>Functions</h3>
<p>
<small>Expedia Code Academy</small>
<br>
<img src="static/img/code_academy_logo.png" border="0px">
</p>
</section>
<section>
<h3>Functions</h3>
<p>
Functions are bits of code that are <i>reusable</i>. This is handy because:<br>
<ul>
<li class="fragment">You don't have to type as much</li>
<li class="fragment">It's easier to read</li>
<li class="fragment">If there's a mistake you only need to fix it once!</li>
</ul>
</p>
<div class="fragment">
Examples:
<pre><code class="python" data-trim>
# The print function with 1 argument: a string
print("hello")
# The len function with 1 argument: a list
len([0, 1, 2, 3])
</code></pre>
</div>
</section>
<section>
<h3>Creating your own functions</h3>
<p>
<br>The syntax involves these key words: <span id="code">def</span> and <span id="code">return</span><br><br>
Here's a function that adds 2 number <i>arguments</i> together:
<pre><code class="python" data-trim>
def add_two_numbers(num1, num2):
result = num1 + num2
return result
# Let's call our function!
sum = add_two_numbers(612, 847)
</code></pre>
</p>
</section>
<section>
<h3>Things to remember</h3>
<p>
<br>Always write your function before you call it!<br>
The below won't work - what error do you get?
<pre><code class="python" data-trim>
# Let's call our function!
sum = add_two_numbers(612, 847)
def add_two_numbers(num1, num2):
result = num1 + num2
return result
</code></pre>
<br>How about this?
<div id="fragment">
<pre><code class="python" data-trim>
sum = add_two_numbers(612, 847, 555)
</code></pre>
</div>
</p>
</section>
<section>
<h3>Different arguments</h3>
<p>
<br>What will <span id="code">sum</span> be in this example?<br><br>
<pre><code class="python" data-trim>
def add_two_numbers(num1, num2):
result = num1 + num2
return result
sum = add_two_numbers('my hovercraft is ', 'full of eels')
</code></pre>
</p>
</section>
<section>
<h3>Exercises</h3>
<ul>
<li>(⭐️) 7a. Write a function that multiplies 2 numbers and returns the result</li>
<li>(⭐️⭐️) 7b. Write a function that multiplies all the numbers in a list together</li>
<br>
<li>See <a href="https://github.com/python101ldn/exercises/blob/master/Session_7/supermarket.py">here</a> for the next exercises!</li>
</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',
slideNumber: true
});
</script>
</body>
</html>