Skip to content

Commit 9e17cc5

Browse files
authored
Merge pull request #350 from dstndstn/typo-fixes
Minor fixes: typos, grammar, formatting, minor clarifications
2 parents c72ec46 + 3795acb commit 9e17cc5

File tree

8 files changed

+67
-65
lines changed

8 files changed

+67
-65
lines changed

_episodes/01-numpy.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ keypoints:
1919
- "Variables are created on demand whenever a value is assigned to them."
2020
- "Use `print(something)` to display the value of `something`."
2121
- "The expression `array.shape` gives the shape of an array."
22-
- "Use `array[x, y]` to select a single element from an array."
22+
- "Use `array[x, y]` to select a single element from a 2D array."
2323
- "Array indices start at 0, not 1."
24-
- "Use `low:high` to specify a slice that includes the indices from `low` to `high-1`."
24+
- "Use `low:high` to specify a `slice` that includes the indices from `low` to `high-1`."
2525
- "All the indexing and slicing that works on arrays also works on strings."
2626
- "Use `# some kind of explanation` to add comments to programs."
2727
- "Use `numpy.mean(array)`, `numpy.max(array)`, and `numpy.min(array)` to calculate simple statistics."
@@ -30,6 +30,7 @@ keypoints:
3030
---
3131
In this lesson we will learn how to manipulate the inflammation dataset with Python. But before we discuss how to deal with many data points, we will show how to store a single value on the computer.
3232

33+
3334
The line below [assigns](reference.html#assignment) the value `55` to a [variable](reference.html#variable) `weight_kg`:
3435

3536
~~~
@@ -169,7 +170,7 @@ Importing a library is like getting a piece of lab equipment out of a storage lo
169170
Libraries provide additional functionality to the basic Python package,
170171
much like a new piece of equipment adds functionality to a lab space. Just like in the lab, importing too many libraries
171172
can sometimes complicate and slow down your programs - so we only import what we need for each program.
172-
Once you've imported the library,
173+
Once we've imported the library,
173174
we can ask the library to read our data file for us:
174175
175176
~~~
@@ -308,7 +309,7 @@ because they have the same part-and-whole relationship.
308309
309310
If we want to get a single number from the array,
310311
we must provide an [index]({{ page.root }}/reference/#index) in square brackets,
311-
just as we do in math:
312+
just as we do in math when referring to an element of a matrix. Our inflammation data has two dimensions, so we will need to use two indices to refer to a value:
312313
313314
~~~
314315
print('first value in data:', data[0, 0])
@@ -558,7 +559,7 @@ standard deviation: 4.61383319712
558559
>
559560
> How did we know what functions NumPy has and how to use them?
560561
> If you are working in the IPython/Jupyter Notebook there is an easy way to find out.
561-
> If you type the name of something with a full-stop then you can use tab completion
562+
> If you type the name of something followed by a dot, then you can use tab completion
562563
> (e.g. type `numpy.` and then press tab)
563564
> to see a list of all functions and attributes that you can use. After selecting one you
564565
> can also add a question mark (e.g. `numpy.cumprod?`) and IPython will return an
@@ -573,7 +574,7 @@ One way to do this is to create a new temporary array of the data we want,
573574
then ask it to do the calculation:
574575
575576
~~~
576-
patient_0 = data[0, :] # 0 on the first axis, everything on the second
577+
patient_0 = data[0, :] # 0 on the first axis (rows), everything on the second (columns)
577578
print('maximum inflammation for patient 0:', patient_0.max())
578579
~~~
579580
{: .python}
@@ -584,7 +585,7 @@ maximum inflammation for patient 0: 18.0
584585
{: .output}
585586
586587
Everything in a line of code following the '#' symbol is a
587-
[comment]({{ page.root }}/reference/#comment) that is ignored by the computer.
588+
[comment]({{ page.root }}/reference/#comment) that is ignored by Python.
588589
Comments allow programmers to leave explanatory notes for other
589590
programmers or their future selves.
590591

_episodes/02-loop.md

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ exercises: 0
55
questions:
66
- "How can I do the same operations on many different values?"
77
objectives:
8-
- "Explain what a for loop does."
9-
- "Correctly write for loops to repeat simple calculations."
8+
- "Explain what a `for` loop does."
9+
- "Correctly write `for` loops to repeat simple calculations."
1010
- "Trace changes to a loop variable as the loop runs."
11-
- "Trace changes to other variables as they are updated by a for loop."
11+
- "Trace changes to other variables as they are updated by a `for` loop."
1212
keypoints:
1313
- "Use `for variable in sequence` to process the elements of a sequence one at a time."
14-
- "The body of a for loop must be indented."
14+
- "The body of a `for` loop must be indented."
1515
- "Use `len(thing)` to determine the length of something that contains other values."
1616
---
1717

@@ -34,7 +34,7 @@ word = 'lead'
3434
{: .python}
3535

3636
We can access a character in a string using its index. For example, we can get the first
37-
character of the word 'lead', by using word[0]. One way to print each character is to use
37+
character of the word `'lead'`, by using `word[0]`. One way to print each character is to use
3838
four `print` statements:
3939

4040
~~~
@@ -151,18 +151,13 @@ The numbers in the diagram denote which loop cycle the character was printed in
151151
We can call the [loop variable]({{ page.root }}/reference/#loop-variable) anything we like,
152152
but there must be a colon at the end of the line starting the loop,
153153
and we must indent anything we want to run inside the loop. Unlike many other languages, there is no
154-
command to signify the end of the loop body (e.g. end for); what is indented after the for statement belongs to the loop.
154+
command to signify the end of the loop body (e.g. `end for`); what is indented after the `for` statement belongs to the loop.
155155

156156

157-
> ## What's in a name?
157+
> ## What's in a name?{.callout}
158158
>
159-
> In the example above, the loop variable was given the name `char`
160-
> as a mnemonic; it is short for 'character'.
161-
> 'Char' is not a keyword in Python that pulls the characters
162-
> from words or strings.
163-
> In fact when a similar loop is run over a list rather than a word,
164-
> the output would be each member of that list printed in order,
165-
> rather than the characters.
159+
>
160+
> In the example above, the loop variable was given the name `char` as a mnemonic; it is short for 'character'. 'Char' is not a keyword in Python that pulls the characters from words or strings. In fact when a similar loop is run over a list rather than a word, the output would be each member of that list printed in order, rather than the characters.
166161
>
167162
> ~~~
168163
> elements = ['oxygen', 'nitrogen', 'argon']
@@ -178,10 +173,7 @@ command to signify the end of the loop body (e.g. end for); what is indented aft
178173
> ~~~
179174
> {: .output}
180175
>
181-
> We can choose any name we want for variables.
182-
> We might just as easily have chosen the name `banana`
183-
> for the loop variable,
184-
> as long as we use the same name when we invoke the variable inside the loop:
176+
> We can choose any name we want for variables. We might just as easily have chosen the name `banana` for the loop variable, as long as we use the same name when we invoke the variable inside the loop:
185177
>
186178
> ~~~
187179
> word = 'oxygen'
@@ -200,9 +192,7 @@ command to signify the end of the loop body (e.g. end for); what is indented aft
200192
> ~~~
201193
> {: .output}
202194
>
203-
> It is a good idea to choose variable names
204-
> that are meaningful so that it is easier
205-
> to understand what the loop is doing.
195+
> It is a good idea to choose variable names that are meaningful, otherwise it would be more difficult to understand what the loop is doing.
206196
{: .callout}
207197
208198
Here's another loop that repeatedly updates a variable:
@@ -278,14 +268,19 @@ so we should always use it when we can.
278268
279269
> ## From 1 to N
280270
>
281-
> Python has a built-in function called `range` that creates a sequence of numbers. Range can
282-
> accept 1-3 parameters. If one parameter is input, range creates an array of that length,
283-
> starting at zero and incrementing by 1. If 2 parameters are input, range starts at
284-
> the first and ends just before the second, incrementing by one. If range is passed 3 parameters,
285-
> it starts at the first one, ends just before the second one, and increments by the third one. For
286-
> example,
287-
> `range(3)` produces the numbers 0, 1, 2, while `range(2, 5)` produces 2, 3, 4,
288-
> and `range(3, 10, 3)` produces 3, 6, 9.
271+
> Python has a built-in function called `range` that creates a sequence of numbers. `range` can
272+
> accept 1, 2, or 3 parameters.
273+
>
274+
> * If one parameter is given, `range` creates an array of that length,
275+
> starting at zero and incrementing by 1.
276+
> For example, `range(3)` produces the numbers `0, 1, 2`.
277+
> * If two parameters are given, `range` starts at
278+
> the first and ends just before the second, incrementing by one.
279+
> For example, `range(2, 5)` produces `2, 3, 4`.
280+
> * If `range` is given 3 parameters,
281+
> it starts at the first one, ends just before the second one, and increments by the third one.
282+
> For exmaple `range(3, 10, 2)` produces `3, 5, 7, 9`.
283+
>
289284
> Using `range`,
290285
> write a loop that uses `range` to print the first 3 natural numbers:
291286
>

_episodes/04-files.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ exercises: 0
55
questions:
66
- "How can I do the same operations on many different files?"
77
objectives:
8-
- "Use a library function to get a list of filenames that match a simple wildcard pattern."
9-
- "Write a for loop to process multiple files."
8+
- "Use a library function to get a list of filenames that match a wildcard pattern."
9+
- "Write a `for` loop to process multiple files."
1010
keypoints:
1111
- "Use `glob.glob(pattern)` to create a list of files whose names match a pattern."
1212
- "Use `*` in a pattern to match zero or more characters, and `?` to match any single character."
@@ -141,6 +141,7 @@ where the maxima are a bit less regular, but the minima are consistently zero.
141141
> composite_data = numpy.zeros((60,40))
142142
> for f in filenames:
143143
> # sum each new file's data into as it's read
144+
> #
144145
> # and then divide the composite_data by number of samples
145146
> composite_data /= len(filenames)
146147
> ~~~

_episodes/05-cond.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ keypoints:
1111
- "Use `if condition` to start a conditional statement, `elif condition` to provide additional tests, and `else` to provide a default."
1212
- "The bodies of the branches of conditional statements must be indented."
1313
- "Use `==` to test for equality."
14-
- "`X and Y` is only true if both X and Y are true."
15-
- "`X or Y` is true if either X or Y, or both, are true."
14+
- "`X and Y` is only true if both `X` and `Y` are true."
15+
- "`X or Y` is true if either `X` or `Y`, or both, are true."
1616
- "Zero, the empty string, and the empty list are considered false; all other numbers, strings, and lists are considered true."
1717
- "Nest loops to operate on multi-dimensional data."
1818
- "Put code whose parameters change frequently in a function, then call it with different parameter values to customize its behavior."
@@ -199,13 +199,7 @@ freeing us from having to manually examine every plot for features we've seen be
199199

200200
> ## How Many Paths?
201201
>
202-
> Which of the following would be printed if you were to run this code?
203-
> Why did you pick this answer?
204-
>
205-
> 1. A
206-
> 2. B
207-
> 3. C
208-
> 4. B and C
202+
> Consider this code:
209203
>
210204
> ~~~
211205
> if 4 > 5:
@@ -217,6 +211,14 @@ freeing us from having to manually examine every plot for features we've seen be
217211
> ~~~
218212
> {: .python}
219213
>
214+
> Which of the following would be printed if you were to run this code?
215+
> Why did you pick this answer?
216+
>
217+
> 1. A
218+
> 2. B
219+
> 3. C
220+
> 4. B and C
221+
>
220222
> > ## Solution
221223
> > C gets printed because the first two conditions, `4 > 5` and `4 == 5`, are not true,
222224
> > but `4 < 5` is true.
@@ -339,7 +341,7 @@ freeing us from having to manually examine every plot for features we've seen be
339341
> >
340342
> > Here `pass` means "don't do anything".
341343
> In this particular case, it's not actually needed, since if `num == 0` neither
342-
> > sum needs to change, but it illustrates the use of `elif`.
344+
> > sum needs to change, but it illustrates the use of `elif` and `pass`.
343345
> {: .solution}
344346
{: .challenge}
345347

_episodes/06-func.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ on a different dataset or at a different point in our program?
3939
Cutting and pasting it is going to make our code get very long and very repetitive,
4040
very quickly.
4141
We'd like a way to package our code so that it is easier to reuse,
42-
and Python provides for this by letting us define things called 'functions' -
42+
and Python provides for this by letting us define things called 'functions' ---
4343
a shorthand way of re-executing longer pieces of code.
4444

4545
Let's start by defining a function `fahr_to_kelvin` that converts temperatures from Fahrenheit to Kelvin:
@@ -720,10 +720,10 @@ numpy.loadtxt('inflammation-01.csv', ',')
720720
721721
then the filename is assigned to `fname` (which is what we want),
722722
but the delimiter string `','` is assigned to `dtype` rather than `delimiter`,
723-
because `dtype` is the second parameter in the list. However ',' isn't a known `dtype` so
723+
because `dtype` is the second parameter in the list. However `','` isn't a known `dtype` so
724724
our code produced an error message when we tried to run it.
725725
When we call `loadtxt` we don't have to provide `fname=` for the filename because it's the
726-
first item in the list, but if we want the ',' to be assigned to the variable `delimiter`,
726+
first item in the list, but if we want the `','` to be assigned to the variable `delimiter`,
727727
we *do* have to provide `delimiter=` for the second parameter since `delimiter` is not
728728
the second parameter in the list.
729729
@@ -831,8 +831,8 @@ readable code!
831831
>
832832
> Write a function `rescale` that takes an array as input
833833
> and returns a corresponding array of values scaled to lie in the range 0.0 to 1.0.
834-
> (Hint: If $L$ and $H$ are the lowest and highest values in the original array,
835-
> then the replacement for a value $v$ should be $(v-L) / (H-L)$.)
834+
> (Hint: If `L` and `H` are the lowest and highest values in the original array,
835+
> then the replacement for a value `v` should be `(v-L) / (H-L)`.)
836836
>
837837
> > ## Solution
838838
> > ~~~
@@ -873,7 +873,7 @@ readable code!
873873
874874
> ## Defining Defaults
875875
>
876-
> Rewrite the `rescale` function so that it scales data to lie between 0.0 and 1.0 by default,
876+
> Rewrite the `rescale` function so that it scales data to lie between `0.0` and `1.0` by default,
877877
> but will allow the caller to specify lower and upper bounds if they want.
878878
> Compare your implementation to your neighbor's:
879879
> do the two functions always behave the same way?
@@ -894,7 +894,7 @@ readable code!
894894
895895
> ## Variables Inside and Outside Functions
896896
>
897-
> What does the following piece of code display when run - and why?
897+
> What does the following piece of code display when run --- and why?
898898
>
899899
> ~~~
900900
> f = 0
@@ -976,12 +976,7 @@ readable code!
976976
977977
> ## The Old Switcheroo
978978
>
979-
> Which of the following would be printed if you were to run this code? Why did you pick this answer?
980-
>
981-
> 1. `7 3`
982-
> 2. `3 7`
983-
> 3. `3 3`
984-
> 4. `7 7`
979+
> Consider this code:
985980
>
986981
> ~~~
987982
> a = 3
@@ -997,6 +992,14 @@ readable code!
997992
> print(a, b)
998993
> ~~~
999994
> {: .python}
995+
>
996+
> Which of the following would be printed if you were to run this code? Why did you pick this answer?
997+
>
998+
> 1. `7 3`
999+
> 2. `3 7`
1000+
> 3. `3 3`
1001+
> 4. `7 7`
1002+
>
10001003
> > ## Solution
10011004
> > `3, 7` is correct. Initially `a` has a value of 3 and `b` has a value of 7.
10021005
> > When the swap function is called, it creates local variables (also called

_episodes/07-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Variable name errors come with some of the most informative error messages,
239239
which are usually of the form "name 'the_variable_name' is not defined".
240240
241241
Why does this error message occur?
242-
That's harder question to answer,
242+
That's a harder question to answer,
243243
because it depends on what your code is supposed to do.
244244
However,
245245
there are a few very common reasons why you might have an undefined variable.

_episodes/09-debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Replacing random chunks of code is unlikely to do much good.
151151
if you got it wrong the first time,
152152
you'll probably get it wrong the second and third as well.)
153153
Good programmers therefore
154-
*change one thing at a time, for a reason*
154+
*change one thing at a time, for a reason*.
155155
They are either trying to gather more information
156156
("is the bug still there if we change the order of the loops?")
157157
or test a fix

_episodes/10-cmdline.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ $ python count_stdin.py small-01.csv
585585
~~~
586586
{: .bash}
587587
588-
i.e., to forget the `<` character that redirect the file to standard input.
588+
i.e., to forget the `<` character that redirects the file to standard input.
589589
In this case,
590590
there's nothing in standard input,
591591
so the program waits at the start of the loop for someone to type something on the keyboard.
@@ -985,7 +985,7 @@ the program now does everything we set out to do.
985985
>
986986
> Write a program called `check_arguments.py` that prints usage
987987
> then exits the program if no arguments are provided.
988-
> (Hint) You can use `sys.exit()` to exit the program.
988+
> (Hint: You can use `sys.exit()` to exit the program.)
989989
>
990990
> ~~~
991991
> $ python check_arguments.py

0 commit comments

Comments
 (0)