Skip to content

Commit ac578a0

Browse files
committed
Update README.md
ToC and formatting updates.
1 parent 855642c commit ac578a0

File tree

1 file changed

+59
-49
lines changed

1 file changed

+59
-49
lines changed

2020_07_14_course/README.md

+59-49
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Thank you for taking the time to read this write-up on the Python introductory c
1717
- [Lists](#lists)
1818
- [Functions](#functions)
1919
- [Lambdas](#lambdas)
20-
21-
20+
- [Loops and `if` Statements](#loops-and-if-statements)
21+
- [`while` Loops](#while-loops)
22+
- [`for` Loops](#for-loops)
23+
- [`if` / `else`/ `elif` Statements](#if--else-elif-statements)
2224

2325
## Setting up Python
2426

@@ -32,11 +34,11 @@ For beginners we recommend using Microsoft's open-source [VSCode editor](https:/
3234

3335
Some extensions we recommend for Python development with VSCode include:
3436

35-
- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) by Microsoft: Enables Python language support in VSCode and test tools.
36-
- [Kite](https://marketplace.visualstudio.com/items?itemName=kiteco.kite): A coding assistant that aids with autocompletion and shows docstrings.
37-
- [Wolf](https://marketplace.visualstudio.com/items?itemName=traBpUkciP.wolf): Live Python scratchpad
38-
- [Sort Lines](https://tyriar.gallerycdn.vsassets.io/extensions/tyriar/sort-lines/1.9.0/1573941482699/Microsoft.VisualStudio.Services.Icons.Small): Automatically sort lines of long dictionary keys.
39-
- [Guides](https://marketplace.visualstudio.com/items?itemName=spywhere.guides): Adds extra indentation guides.
37+
- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) by Microsoft: Enables Python language support in VSCode and test tools.
38+
- [Kite](https://marketplace.visualstudio.com/items?itemName=kiteco.kite): A coding assistant that aids with autocompletion and shows docstrings.
39+
- [Wolf](https://marketplace.visualstudio.com/items?itemName=traBpUkciP.wolf): Live Python scratchpad
40+
- [Sort Lines](https://tyriar.gallerycdn.vsassets.io/extensions/tyriar/sort-lines/1.9.0/1573941482699/Microsoft.VisualStudio.Services.Icons.Small): Automatically sort lines of long dictionary keys.
41+
- [Guides](https://marketplace.visualstudio.com/items?itemName=spywhere.guides): Adds extra indentation guides.
4042

4143
## Downloading Packages
4244

@@ -130,7 +132,7 @@ Accessing values in dictionaries happens a little differently, since they're all
130132

131133
#### Lists
132134

133-
Lists do exactly what the name suggests. They let you store multiple variables in them, and access them via *indices* later on. Indices begin from 0 - being the first element, and progress upwards. Let's take a look at an example:
135+
Lists do exactly what the name suggests. They let you store multiple variables in them, and access them via _indices_ later on. Indices begin from 0 - being the first element, and progress upwards. Let's take a look at an example:
134136

135137
```python
136138
my_list = [1, 1.5, "test", True]
@@ -190,62 +192,71 @@ print(multiply(5, 2))
190192

191193
Lambdas automatically return the value they're assigned to, so the `return` keyword can be omitted.
192194

193-
### Loops and If statements
195+
### Loops and `if` Statements
196+
197+
#### `while` Loops
194198

195-
#### While loops
196199
While loops work by running a certain piece of code while a given statement is true. So for example if you wanted to print all numbers up to 10 with a while statement, you would do this:
200+
197201
```py
198202
i = 0
199203
while i<10:
200204
print(i)
201205
i += 1 # increment the counter
202206
```
207+
203208
A trace table for this can be seen here:
209+
204210
```markdown
205-
| Iteration | I | While | Output |
206-
|-----------|----|-------|-----------|
207-
| 1 | 0 | True | 0 |
208-
| 2 | 1 | True | 1 |
209-
| 3 | 2 | True | 2 |
210-
| 4 | 3 | True | 3 |
211-
| 5 | 4 | True | 4 |
212-
| 6 | 5 | True | 5 |
213-
| 7 | 6 | True | 6 |
214-
| 8 | 7 | True | 7 |
215-
| 9 | 8 | True | 8 |
216-
| 10 | 9 | True | 9 |
217-
| 11 | 10 | False | No output |
211+
| Iteration | I | While | Output |
212+
| --------- | --- | ----- | --------- |
213+
| 1 | 0 | True | 0 |
214+
| 2 | 1 | True | 1 |
215+
| 3 | 2 | True | 2 |
216+
| 4 | 3 | True | 3 |
217+
| 5 | 4 | True | 4 |
218+
| 6 | 5 | True | 5 |
219+
| 7 | 6 | True | 6 |
220+
| 8 | 7 | True | 7 |
221+
| 9 | 8 | True | 8 |
222+
| 10 | 9 | True | 9 |
223+
| 11 | 10 | False | No output |
218224
```
219-
#### For loops
225+
226+
#### `for` Loops
227+
220228
For loops are similar to while loops however they work with ranges. These ranges can be different things, you can have ranges between numbers but similarly you can have ranges on strings. We will replicate the numbers between 1 and 10 with a for loop.
229+
221230
```py
222231
for i in range(0,10):
223232
print(i)
224233
```
234+
225235
As you can see this is much more efficient, you do not need to increment the variable manually or even initialise it, the for loop does this itself. As stated above you can also do this on strings so i will show this below too:
236+
226237
```py
227238
my_str = "hello world"
228239
for i in my_str:
229240
print(i)
230-
"""
231-
Output:
232-
h
233-
e
234-
l
235-
l
236-
o
237-
238-
w
239-
o
240-
r
241-
l
242-
d
243-
"""
241+
>>> h
242+
>>> e
243+
>>> l
244+
>>> l
245+
>>> o
246+
>>>
247+
>>> w
248+
>>> o
249+
>>> r
250+
>>> l
251+
>>> d
244252
```
245-
As you can see it goes over each character individually, in an iterative process.
246253

247-
#### If / else/ elif statements
254+
As you can see it goes over each character individually, in an iterative process.
255+
256+
#### `if` / `else`/ `elif` Statements
257+
248258
If statements are a fundamental concept in the majority of programming languages and python is no different, this is used to check if a given condition is true. If it is then it will execute the code it is supplied if not it will go to through elif until one is true (if supplied) if none are true then it will go to the else statement. An example of this will be:
259+
249260
```py
250261
age = int(input("Enter your age"))
251262
if age < 18:
@@ -255,14 +266,13 @@ elif age > 18:
255266
else:
256267
print('Please provide ID, 18 year olds must be checked')
257268

258-
"""
259269
>>> Enter your age
260-
>18
261-
Please provide ID, 18 year olds must be checked
270+
> 18
271+
>>> Please provide ID, 18 year olds must be checked
272+
>>> Enter your age
273+
> 16
274+
>>> You cannot enter the club
262275
>>> Enter your age
263-
>16
264-
You cannot enter the club
265-
>>>Enter your age
266-
>38
267-
Welcome to the club
268-
"""
276+
> 38
277+
>>> Welcome to the club
278+
```

0 commit comments

Comments
 (0)