forked from PythonCourses/PythonCourses.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
235 lines (152 loc) · 13.3 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Code For Fun - Python Courses</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta property="og:type" content="website">
<meta property="og:title" content="Code For Fun - Python Courses">
<meta property="og:url" content="http://PythonCourses.github.io/index.html">
<meta property="og:site_name" content="Code For Fun - Python Courses">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Code For Fun - Python Courses">
<link rel="alternate" href="/atom.xml" title="Code For Fun - Python Courses" type="application/atom+xml">
<link rel="icon" href="/favicon.png">
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div id="container">
<div id="wrap">
<header id="header">
<div id="banner"></div>
<div id="header-outer" class="outer">
<div id="header-title" class="inner">
<h1 id="logo-wrap">
<a href="/" id="logo">Code For Fun - Python Courses</a>
</h1>
</div>
<div id="header-inner" class="inner">
<nav id="main-nav">
<a id="main-nav-toggle" class="nav-icon"></a>
<a class="main-nav-link" href="/">Home</a>
<a class="main-nav-link" href="/archives">Archives</a>
</nav>
<nav id="sub-nav">
<a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
<a id="nav-search-btn" class="nav-icon" title="Zoeken"></a>
</nav>
<div id="search-form-wrap">
<form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit"></button><input type="hidden" name="sitesearch" value="http://PythonCourses.github.io"></form>
</div>
</div>
</div>
</header>
<div class="outer">
<section id="main">
<article id="post-Lesson-2" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/12/30/Lesson-2/" class="article-date">
<time datetime="2016-12-30T22:40:07.000Z" itemprop="datePublished">12-30-2016</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/12/30/Lesson-2/">Lesson 2</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
</div>
<footer class="article-footer">
<a data-url="http://PythonCourses.github.io/2016/12/30/Lesson-2/" data-id="cixcdwlol0001uf3v8plu02bu" class="article-share-link">Delen</a>
</footer>
</div>
</article>
<article id="post-Lesson-1" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/2016/12/30/Lesson-1/" class="article-date">
<time datetime="2016-12-30T19:50:12.000Z" itemprop="datePublished">12-30-2016</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/12/30/Lesson-1/">Lesson 1</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<p>This lesson is all about the basics. We are going to accomplish alot! We are going to be:</p>
<ol>
<li><strong> Printing so we can see the output of our program </strong></li>
<li><strong> Assigning number values to variables using Ints </strong></li>
<li><strong> Assigning text values to variables using Strings </strong></li>
<li><strong> Performing mathematical operations on variables </strong></li>
<li><strong> Changing variable types using Typecasting </strong></li>
<li><strong> Creating and calling our own functions </strong></li>
<li><strong> Customizing our functions to have Paramaters and Return Values </strong></li>
</ol>
<p>This may seem like a lot to handle, but you will pick up on it pretty quickly. So lets get started. </p>
<h2 id="Output-and-Variables"><a href="#Output-and-Variables" class="headerlink" title="Output and Variables"></a>Output and Variables</h2><h3 id="1-1-Hello-World-Getting-Output-From-Our-Program"><a href="#1-1-Hello-World-Getting-Output-From-Our-Program" class="headerlink" title="1-1 Hello World - Getting Output From Our Program"></a>1-1 Hello World - Getting Output From Our Program</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">print("Hello World")</div></pre></td></tr></table></figure>
<h3 id="1-2-Our-First-Variable-Assigning-Values"><a href="#1-2-Our-First-Variable-Assigning-Values" class="headerlink" title="1-2 Our First Variable - Assigning Values"></a>1-2 Our First Variable - Assigning Values</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mathResult = 2+2</div><div class="line">print(mathResult)</div></pre></td></tr></table></figure>
<h3 id="1-3-Multiple-Variables"><a href="#1-3-Multiple-Variables" class="headerlink" title="1-3 Multiple Variables"></a>1-3 Multiple Variables</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">favoriteNumber = 14</div><div class="line">age = 13 </div><div class="line">combo = favoriteNumber + age</div><div class="line">print(combo)</div></pre></td></tr></table></figure>
<h3 id="1-4-Combining-Strings-Together-Concatenation"><a href="#1-4-Combining-Strings-Together-Concatenation" class="headerlink" title="1-4 Combining Strings Together - Concatenation"></a>1-4 Combining Strings Together - Concatenation</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">name = "Pat"</div><div class="line">favouriteFood = "Pizza"</div><div class="line">greeting = "Hello my name is " + name + " and my favorite food is " + favouriteFood </div><div class="line">print(greeting)</div></pre></td></tr></table></figure>
<h3 id="1-5-Type-Casting-Variables"><a href="#1-5-Type-Casting-Variables" class="headerlink" title="1-5: Type Casting Variables"></a>1-5: Type Casting Variables</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">name = "Pat"</div><div class="line">age = 14</div><div class="line">greeting = "Hello my name is " + name + " and I am " + age + " years old"</div><div class="line">print(greeting)</div></pre></td></tr></table></figure>
<h2 id="HOLD-UP"><a href="#HOLD-UP" class="headerlink" title="HOLD UP!"></a>HOLD UP!</h2><p>Why didn’t the above program work!?<br>Well our age variable is set to 14, so it has type Int. So we add it to the String in greeting, we are<br>concatenating an Int type to a String type, which is a Type error. We cannot do operations on different Types. So we must change the Int type to a String type using <strong> TypeCasting </strong>.</p>
<p>We can doing this by wrapping the age variable in the str() function, like so: <strong> str(age) </strong><br>So lets change line 3 in our program to look like this: </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">greeting = "Hello my name is " + name + " and I am " + str(age) + " years old"</div></pre></td></tr></table></figure>
<h2 id="Functions"><a href="#Functions" class="headerlink" title="Functions"></a>Functions</h2><p>Functions are simply blocks of code that we can execute anywhere in our program. It allows us to break our program up in to tasks, so when we want to accomplish the task, we can simply call the function. </p>
<h3 id="1-6-A-Simple-Function"><a href="#1-6-A-Simple-Function" class="headerlink" title="1-6: A Simple Function"></a>1-6: A Simple Function</h3><p>Lets start of with a basic function. We create functions using the <strong> def </strong> keyword, followed by the function name, then parenthesis, then a colon. We then indent. When we indent, we are putting the indenting code into a <strong> block </strong>. In this case, everything in the this block, which is just the print command, is part of the function.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">def sayHello():</div><div class="line"> print("Hello")</div><div class="line"></div><div class="line">sayHello()</div></pre></td></tr></table></figure></p>
<h3 id="1-7-Function-Paramaters"><a href="#1-7-Function-Paramaters" class="headerlink" title="1-7: Function Paramaters"></a>1-7: Function Paramaters</h3><p>The sayHello() function is nice, but it just does the same thing every time… kinda boring :/.<br>What if we want the function to do something diferent based on some data that we give it?<br>Easy! That’s what <strong> paramaters </strong> are for. For example, we can create a function that gives us the square of a number. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">def squareNumber(number):</div><div class="line"> square = number * number</div><div class="line"> print(square)</div><div class="line"></div><div class="line">squareNumber(1)</div><div class="line">squareNumber(2)</div><div class="line">squareNumber(3)</div><div class="line">squareNumber(4)</div><div class="line">squareNumber(5)</div></pre></td></tr></table></figure>
<h3 id="1-8-Function-Return-Values"><a href="#1-8-Function-Return-Values" class="headerlink" title="1-8: Function Return Values"></a>1-8: Function Return Values</h3><p>It’s cool that we can get functions to do all of this work for us, but it would be nice to store the result of these functions in a variable.<br>That’s where <strong>return values </strong> are handy. We can tell the function to return something to us, and we can assign a variable to it. So lets do this using the squared number example. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">def squareNumber(number):</div><div class="line"> square = number * number</div><div class="line"> return square</div><div class="line"></div><div class="line">number = 5</div><div class="line">square = squareNumber(number)</div><div class="line"></div><div class="line">result = str(number) + " squared is equal to " + str(square)</div><div class="line">print(result)</div><div class="line"></div></pre></td></tr></table></figure>
</div>
<footer class="article-footer">
<a data-url="http://PythonCourses.github.io/2016/12/30/Lesson-1/" data-id="cixcdwlod0000uf3vlfwjrudz" class="article-share-link">Delen</a>
</footer>
</div>
</article>
</section>
<aside id="sidebar">
<div class="widget-wrap">
<h3 class="widget-title">Archieven</h3>
<div class="widget">
<ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/12/">December 2016</a></li></ul>
</div>
</div>
<div class="widget-wrap">
<h3 class="widget-title">Recente berichten</h3>
<div class="widget">
<ul>
<li>
<a href="/2016/12/30/Lesson-2/">Lesson 2</a>
</li>
<li>
<a href="/2016/12/30/Lesson-1/">Lesson 1</a>
</li>
</ul>
</div>
</div>
</aside>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info" class="inner">
© 2016 John Doe<br>
Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
</div>
</div>
</footer>
</div>
<nav id="mobile-nav">
<a href="/" class="mobile-nav-link">Home</a>
<a href="/archives" class="mobile-nav-link">Archives</a>
</nav>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script src="/js/script.js"></script>
</div>
</body>
</html>