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/chapters/c05_if_statements.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -210,6 +210,8 @@ def program(self):
210
210
211
211
212
212
classUnderstandingProgramsWithSnoop(Page):
213
+
title="Understanding Programs With `snoop`"
214
+
213
215
classprint_tail(print_tail_base):
214
216
"""
215
217
Run this program:
@@ -228,15 +230,15 @@ class print_tail(print_tail_base):
228
230
classprint_tail_snoop(print_tail_base):
229
231
"""
230
232
Programs are starting to get complicated!
231
-
It's time to introduce a new tool to help you understand programs. Click the'Snoop' button to run the same program while also showing what's happening.
233
+
It's time to introduce a new tool to help you understand programs. Click the`snoop` button to run the same program while also showing what's happening.
232
234
"""
233
235
234
236
program_in_text=False
235
237
expected_code_source="snoop"
236
238
237
239
classprint_first_character(ExerciseStep):
238
240
"""
239
-
Tada! Scroll to the top of the terminal and let's walk through what snoop is showing you.
241
+
Tada! Scroll to the top of the terminal and let's walk through what`snoop` is showing you.
240
242
It starts out very straightforward:
241
243
242
244
1 | sentence = 'Hello World'
@@ -248,9 +250,9 @@ class print_first_character(ExerciseStep):
248
250
The first lines are simply showing you the lines of the program that the computer ran.
249
251
On the left is the line number as seen in the editor.
250
252
251
-
Running `for char in sentence:` assigns a value to the variable `char`, so snoop shows you that value.
253
+
Running `for char in sentence:` assigns a value to the variable `char`, so`snoop` shows you that value.
252
254
Lines starting with `......` indicate a new variable or a change in the value of an existing variable.
253
-
Such lines will not be shown when they're redundant, which is why the snoop output doesn't start like this:
255
+
Such lines will not be shown when they're redundant, which is why the`snoop` output doesn't start like this:
You've seenSnoop and Python Tutor. futurecoder comes with one last tool to analyse programs as they run, called*Bird's Eye*.
1109
+
You've seen`snoop` and Python Tutor. futurecoder comes with one last tool to analyse programs as they run, called`birdseye`.
1110
1110
1111
-
Here's an example program to run. Copy it into the editor and click theBird's Eye button. This will open a new browser tab with the visualisation.
1111
+
Here's an example program to run. Copy it into the editor and click the`birdseye` button. This will open a new browser tab with the visualisation.
1112
1112
1113
1113
__copyable__
1114
1114
__program_indented__
@@ -1125,13 +1125,13 @@ def program(self):
1125
1125
1126
1126
classbirdseye_loop_example(VerbatimStep):
1127
1127
"""
1128
-
While the other tools show how code runs line by line and the values of variables,Bird's Eye shows you the value of every expression in a program. This lets you see how a complex expression is broken down into smaller sub-expressions
1128
+
While the other tools show how code runs line by line and the values of variables,`birdseye` shows you the value of every expression in a program. This lets you see how a complex expression is broken down into smaller sub-expressions
1129
1129
and what the value of each one is.
1130
1130
1131
1131
Hover your mouse over the various boxed expressions in the last line of the program.
1132
1132
As each box is highlighted, its value is shown at the bottom of the screen. Clicking on the box will stick it on a panel so you can see several expression values at once and move your mouse around freely.
1133
1133
1134
-
In this caseBird's Eye shows that the expression:
1134
+
In this case`birdseye` shows that the expression:
1135
1135
1136
1136
a * b + c * d
1137
1137
@@ -1145,7 +1145,7 @@ class birdseye_loop_example(VerbatimStep):
1145
1145
1146
1146
In other words, Python follows the usual order of operations in maths, rather than just evaluating from left to right.
1147
1147
1148
-
Note that there are some expressions thatBird's Eye doesn't put in a box. In this case `2`, `3`, `4`, `5`, and `print` are all expressions as well, but their values are obvious and boxing them would just be clutter.
1148
+
Note that there are some expressions that`birdseye` doesn't put in a box. In this case `2`, `3`, `4`, `5`, and `print` are all expressions as well, but their values are obvious and boxing them would just be clutter.