Skip to content

Commit 68a3624

Browse files
committed
rewrite intro/recap part 2
1 parent a69893e commit 68a3624

2 files changed

Lines changed: 53 additions & 34 deletions

File tree

core/recap.md

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,24 @@ But there is a much more interactive and fast way to start using python. Launch
4848
jupyter notebook
4949
```
5050

51-
It will start the python interpreter in the background and show a browser page, that is connected to python and will interactively edit and run your python code.
51+
It will start the python interpreter in the background and show a browser page that is connected to python. The browser will let you interactively edit and run your python code on your local machine. In this tutorial, we will encourage you to use jupyter-notebooks as it is a tool often used in data science. The python code is the same whether you run it interactively in jupyter or not.
5252

53-
Navigate to a directory where you want to start you python project and press the *new* button on the top right of the web page.
53+
In the jupyter browser window, navigate to a directory where you want to start you python project and press the *new* button on the top right of the web page.
5454

55+
![create a new notebook in jupyter](../images/jupyter_new.png)
5556

5657

58+
With jupyter and python running, lets recap some of the basic features of the python language. Type the code into a *cell* in jupyter and execute the cell by pressing the *Run* button or *Shift+Return* on your keyboard.
5759

58-
# Loops
60+
# Python language basics
61+
62+
## Loops
5963

6064
What does this code do?
6165

6266
<div class="jupyter">
6367
```python
64-
for i in 2, 4, 6, 8:
68+
for i in [2, 4, 6, 8]:
6569
print(i)
6670
```
6771

@@ -71,73 +75,88 @@ for i in 2, 4, 6, 8:
7175
8
7276
</div>
7377

74-
### Solution
75-
7678
This code prints the even numbers 2 through 8, one per line.
7779

7880
### Bonus Challenge
7981

8082
Python has a built-in function called `range` that can automatically generate a range of numbers like \[2, 4, 6, 8\]. For example, `range(1,10)` is a sequence of the numbers 1 through 9 (a common but sometimes confusing thing in programming is for the "end" number not to be included in a sequence.)
8183

82-
for i in range(1,10):
83-
print(i)
84+
<div class="jupyter">
85+
```python
86+
for i in range(1,10):
87+
print(i)
88+
```
89+
</div>
8490

85-
Can you make a `range` equivalent to \[2, 4, 6, 8\]? To get some clues, you can open an interactive Python Interpreter and type `help(range)`. The useful details are near the top. Press 'q' to exit the help viewer when you're done.
91+
Can you make a `range` equivalent to \[2, 4, 6, 8\]? To get some clues, type `help(range)`. The useful details are near the top. The help utility is available for most python functions and once you know how to read them, they are very useful.
8692

8793

88-
# Variables
94+
## Variables
8995

9096
You can use variables to manipulate values inside code. What does this code do?
9197

92-
total = 0
93-
for i in 1, 3, 7:
94-
total = total + i
95-
print(total)
98+
<div class="jupyter">
99+
```python
100+
total = 0
101+
for i in 1, 3, 7:
102+
total = total + i
103+
print(total)
104+
```
96105

97-
### Solution
106+
11
107+
</div>
98108

99-
This code prints 11 - the sum of the numbers 1, 3 and 7.
109+
This code prints the sum of the numbers 1, 3 and 7.
100110

101111
### Bonus Challenge
102112

103113
If you don't want to use a `for` loop for some reason, Python actually has a built-in function called `sum` that lets you bypass it completely. You can get the same result with this:
104114

105-
print(sum([1,3,7]))
115+
<div class="jupyter">
116+
```python
117+
print(sum([1,3,7]))
118+
```
119+
</div>
106120

107121
Can you make a one line Python statement that uses both `sum` and `range` to print the sum of the numbers 1 through 10?
108122

109123

110-
# Functions
124+
## Functions
111125

112126
You can define your own functions with parameters in order to reuse some code again with slight differences. What does this code print?
113127

114-
def say_hello_to(name):
115-
print("Hello " + name)
116-
117-
say_hello_to("Miranda")
118-
say_hello_to("Fred")
128+
<div class="jupyter">
129+
```python
130+
def say_hello_to(name):
131+
print("Hello " + name)
119132

120-
### Solution
133+
say_hello_to("Miranda")
134+
say_hello_to("Fred")
135+
```
121136

122137
Hello Miranda
123138
Hello Fred
139+
</div>
124140

125-
126-
# Conditionals
141+
## Conditionals
127142

128143
You can use the 'if' statement to execute some statements only if a condition is true. What does this code print?
129144

130-
angle = 5
131-
if angle > 0:
132-
print("Turning clockwise")
133-
elif angle < 0:
134-
print("Turning anticlockwise")
135-
else:
136-
print("Not turning at all")
145+
<div class="jupyter">
146+
147+
```python
148+
angle = 5
149+
if angle > 0:
150+
print("Turning clockwise")
151+
elif angle < 0:
152+
print("Turning anticlockwise")
153+
else:
154+
print("Not turning at all")
137155

138-
### Solution
156+
```
139157

140158
Turning clockwise
159+
</div>
141160

142161

143162
## Next Chapter

images/jupyter_new.png

40.4 KB
Loading

0 commit comments

Comments
 (0)