-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonTutorial1.html
262 lines (208 loc) · 11 KB
/
PythonTutorial1.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
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="normal" href="favicon-16x16.png">
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/vendor/modernizr-2.8.3.min.js"></script>
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<nav class="navbar">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Konglobemeralt</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="index.html">Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Tutorials <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="PythonTutorial1.html">Crash Course In Python</a></li>
<li><a href="#">Seomthing something</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
<li><a href="blogg.html">Blog</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container-fluid text-center">
<div class="jumbotron">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h1>Crash Course in Python</h1>
<p class="lead">
Part one: Installing python and variables.
</p>
</div>
</div>
</div>
</div>
<div class="container">
<!-- / <p>Cool animerad version:</p>
<div class="fakeMenu container">
<div class="fakeButtons fakeClose"></div>
<div class="fakeButtons fakeMinimize"></div>
<div class="fakeButtons fakeZoom"></div>
</div>
<div class="fakeScreen container">
<p class="terminalP blackLine1">>>> Fake python terminal skapad med CSS som nog kommer se både bättre ut än de statiska bilderna<span class="terminalSpan cursor1">_</span></p>
<p class="terminalP blackLine2" >samt gå att animera lite!<span class="terminalSpan cursor2">_</span></p>
<p class="terminalP redLine3">SyntaxError: invalid syntax</p>
<p class="terminalP blackLine4"> >>> <span class="terminalSpan cursor4">_</span></p>
</div>
-->
<p>A while ago, some friends of mine wanted to learn some basic programming which made me put together a quick and dirty introduction to programming in python.
Now there are a lot of tutorials out there, and a lot of them might actually be better than this one.
But here we go.</p>
<h1><strong>Installing python</strong></h1>
<p>First of all, we will need to install python which you can do by clicking <a href="https://www.python.org/downloads/">here</a> and following the instructions. I reccomend you pick version 2.7.12, but you should be able to follow this tutorial regardless of
which version you choose.</p>
<p>After following all the steps you should be able to find a program called "IDLE" in your start menu or launchpad if you are on a mac, which when started should display something like this:</p>
<br>
<div class="fakeMenu container">
<div class="fakeButtons fakeClose"></div>
<div class="fakeButtons fakeMinimize"></div>
<div class="fakeButtons fakeZoom"></div>
</div>
<div class="fakeScreen container">
<p class="blackP">Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32<br>
Type "copyright", "credits" or "license()" for more information.<br>
</p>
<p class="blackP">>>><span class="terminalSpan cursorInfinite">_</span></p>
</div>
<br>
<p>You are now ready to start telling the computer to do things by giving it instructions! Try entering "5+5" into the terminal window and then press enter. Whatch what happens. Try this out with other numbers and other operators and see what happens.
You can even use parentheses to build as complex expressions as you can imagine. After testing some stuff your window might look like this: </p>
<br>
<div class="fakeMenu container">
<div class="fakeButtons fakeClose"></div>
<div class="fakeButtons fakeMinimize"></div>
<div class="fakeButtons fakeZoom"></div>
</div>
<div class="fakeScreen container">
<p class="blackP">Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32<br>
Type "copyright", "credits" or "license()" for more information.<br>
</p>
<p class="blackP">>>>5+5<br>
</p>
<p class="blueP"> 10
</p>
<p class="blackP">>>>14/3<br>
</p>
<p class="blueP"> 4.666666666666667
</p>
<p class="blackP">>>>3 * 4<br>
</p>
<p class="blueP"> 12
</p>
<p class="blackP">>>>(23 / 4) * (91 + (90 / 10))<br>
</p>
<p class="blueP"> 570.0
</p>
<p class="blackP">>>><span class="terminalSpan cursorInfinite">_</span></p>
</div>
<br>
<p>Instead of remembering and typing each value every time you need it you can instead try assigning it to a variable. You might remember from math how a letter can be used to represent a numerical quantity and this is
not that different. <br>
Try writing "X = 100" for example and then press enter. It may look like nothing has happend but what you actually have done is created a sort of box in which the computer now stores the value 100. </p>
Now everytime you need that value you can just write X instead. Try adding 20 to X and see what happens!
<br>
But how about something a little bit more interessting, ok basically the same thing but just to illustrate how it works, try writing "moneyInMyPocket = 250" and pressing enter. As before nothing happens but now you have a variable representing how much money you have in your pocket!
<br> <br>
<div class="fakeMenu container">
<div class="fakeButtons fakeClose"></div>
<div class="fakeButtons fakeMinimize"></div>
<div class="fakeButtons fakeZoom"></div>
</div>
<div class="fakeScreen container">
<p class="blackP">>>>X = 100<br>
</p>
<p class="blackP">>>>X + 20<br>
</p>
<p class="blueP"> 120
</p>
<p class="blackP">>>>moneyInMyPocket = 250<br>
</p>
<p class="blackP">>>><span class="terminalSpan cursorInfinite">_</span></p>
</div>
<br>
<p>You can use this variable in the same way as you use regular numbers. Lets add a few variables and try this out. </p>
<br>
<div class="fakeMenu container">
<div class="fakeButtons fakeClose"></div>
<div class="fakeButtons fakeMinimize"></div>
<div class="fakeButtons fakeZoom"></div>
</div>
<div class="fakeScreen container">
<p class="blackP">>>>moneyInMyPocket = 250<br>
</p>
<p class="blackP">>>>priceOfThing = 50<br>
</p>
<p class="blackP">>>>priceOfanotherThing = 25<br>
</p>
<p class="blackP">>>>moneyInMyPocket - ( priceOfThing + priceOfAnotherThing ) <br>
</p>
<p class="blueP"> 175
</p>
<p class="blackP">>>><span class="terminalSpan cursorInfinite">_</span></p>
</div>
<br>
<p>Note however that if just write moneyInMyPocket it would appear you still have 250 and not 175 as the above equation would suggest. What is going on here? Everytime you use a varialbe you are referencing the value that is stored there. </p>
<br>
</div>
<div class="container-fluid site-footer">
<div class="row">
<div class="col-md-12">
<p>
<span class="glyphicon glyphicon-phone" aria-hidden="true"></span> 0701773030
</p>
<p>
<span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> [email protected]
</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.12.0.min.js"><\/script>')</script>
<script src="js/bootstrap.min.js"></script>
<script src="bower_components/isotope/dist/isotope.pkgd.js"></script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='https://www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','UA-XXXXX-X','auto');ga('send','pageview');
</script>
</body>
</html>