You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/recap.md
+53-34Lines changed: 53 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,20 +48,24 @@ But there is a much more interactive and fast way to start using python. Launch
48
48
jupyter notebook
49
49
```
50
50
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.
52
52
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.
54
54
55
+

55
56
56
57
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.
57
59
58
-
# Loops
60
+
# Python language basics
61
+
62
+
## Loops
59
63
60
64
What does this code do?
61
65
62
66
<divclass="jupyter">
63
67
```python
64
-
for i in2, 4, 6, 8:
68
+
for i in[2, 4, 6, 8]:
65
69
print(i)
66
70
```
67
71
@@ -71,73 +75,88 @@ for i in 2, 4, 6, 8:
71
75
8
72
76
</div>
73
77
74
-
### Solution
75
-
76
78
This code prints the even numbers 2 through 8, one per line.
77
79
78
80
### Bonus Challenge
79
81
80
82
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.)
81
83
82
-
for i in range(1,10):
83
-
print(i)
84
+
<divclass="jupyter">
85
+
```python
86
+
for i inrange(1,10):
87
+
print(i)
88
+
```
89
+
</div>
84
90
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.
86
92
87
93
88
-
# Variables
94
+
##Variables
89
95
90
96
You can use variables to manipulate values inside code. What does this code do?
91
97
92
-
total = 0
93
-
for i in 1, 3, 7:
94
-
total = total + i
95
-
print(total)
98
+
<divclass="jupyter">
99
+
```python
100
+
total =0
101
+
for i in1, 3, 7:
102
+
total = total + i
103
+
print(total)
104
+
```
96
105
97
-
### Solution
106
+
11
107
+
</div>
98
108
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.
100
110
101
111
### Bonus Challenge
102
112
103
113
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:
104
114
105
-
print(sum([1,3,7]))
115
+
<divclass="jupyter">
116
+
```python
117
+
print(sum([1,3,7]))
118
+
```
119
+
</div>
106
120
107
121
Can you make a one line Python statement that uses both `sum` and `range` to print the sum of the numbers 1 through 10?
108
122
109
123
110
-
# Functions
124
+
##Functions
111
125
112
126
You can define your own functions with parameters in order to reuse some code again with slight differences. What does this code print?
113
127
114
-
def say_hello_to(name):
115
-
print("Hello " + name)
116
-
117
-
say_hello_to("Miranda")
118
-
say_hello_to("Fred")
128
+
<divclass="jupyter">
129
+
```python
130
+
defsay_hello_to(name):
131
+
print("Hello "+ name)
119
132
120
-
### Solution
133
+
say_hello_to("Miranda")
134
+
say_hello_to("Fred")
135
+
```
121
136
122
137
Hello Miranda
123
138
Hello Fred
139
+
</div>
124
140
125
-
126
-
# Conditionals
141
+
## Conditionals
127
142
128
143
You can use the 'if' statement to execute some statements only if a condition is true. What does this code print?
0 commit comments