Skip to content

Commit 694a421

Browse files
authored
what I hope is the final pass of the wordy typo monsters. (#3803)
1 parent 7993df7 commit 694a421

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

exercises/practice/wordy/.approaches/functools-reduce/content.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ def answer(question):
1616
raise ValueError("unknown operation")
1717

1818
# Using the built-in filter() to clean & split the question..
19-
list(filter(lambda x:
20-
x not in ("What", "is", "by"),
21-
question.strip("?").split()))
19+
question = list(filter(lambda x:
20+
x not in ("What", "is", "by"),
21+
question.strip("?").split()))
2222

2323
# Separate candidate operators and numbers into two lists.
2424
operations = question[1::2]
2525

2626
# Convert candidate elements to int(), checking for "-".
2727
# All other values are replaced with None.
28-
digits = [int(element) if (element.isdigit() or element[1:].isdigit())
28+
digits = [int(element) if
29+
(element.isdigit() or element[1:].isdigit())
2930
else None for element in question[::2]]
3031

3132
# If there is a mis-match between operators and numbers, toss error.
@@ -106,7 +107,8 @@ def answer(question):
106107

107108
# Convert candidate elements to int(), checking for "-".
108109
# All other values are replaced with None.
109-
digits = [int(element) if (element.isdigit() or element[1:].isdigit())
110+
digits = [int(element) if
111+
(element.isdigit() or element[1:].isdigit())
110112
else None for element in question[::2]]
111113

112114
# If there is a mis-match between operators and numbers, toss error.

exercises/practice/wordy/.approaches/introduction.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ However, solutions all follow the same general steps:
3131
3232
1. Remove the parts of the question string that do not apply to calculating the answer.
3333
2. Iterate over the question, determining which words are numbers, and which are meant to be mathematical operations.
34-
-- _Converting the question string into a `list` of words is hugely helpful here._
34+
_Converting the question string into a `list` of words is hugely helpful here._
3535
3. **_Starting from the left_**, take the first three elements and convert number strings to `int` and operations words to the mathematical operations +, -, *, and /.
3636
4. Apply the operation to the numbers, which should result in a single number.
37-
-- _Employing a `try-except` block can trap any errors thrown and make the code both "safer" and less complex._
37+
_Employing a `try-except` block can trap any errors thrown and make the code both "safer" and less complex._
3838
5. Use the calculated number from step 4 as the start for the next "trio" (_number, operation, number_) in the question. The calculated number + the remainder of the question becomes the question being worked on in the next iteration.
39-
-- _Using a `while-loop` with a test on the length of the question to do calculation is a very common strategy._
39+
_Using a `while-loop` with a test on the length of the question to do calculation is a very common strategy._
4040
6. Once the question is calculated down to a single number, that is the answer. Anything else that happens in the loop/iteration or within the accumulated result is a `ValueError("syntax error")`.
4141
~~~~
4242

exercises/practice/wordy/.approaches/recursion/content.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ For example:
246246

247247
1. "1 plus -10 multiplied by 13 divided by 2" would match on "1 plus -10" (_group x_) **multiplied by** "13 divided by 2" (_group y_).
248248
2. This is re-arranged to `mul(calculate("1 plus -10"), calculate("13 divided by 2"))`
249-
3. At this point the loop would pause as the two recursive calls to `calculate()` spawn
250-
4. The loops then run again — and so would the calls to `calculate()`, until there wasn't any match that caused a split of the question or an error.
251-
5. One at a time, the numbers would then be returned, until the main `mul(calculate("1 plus -10"), calculate("13 divided by 2"))` could be solved, at which point the answer is returned.
249+
3. At this point, the loop pauses as the two recursive calls to `calculate()` spawn
250+
4. The loop runs again — and so do the calls to `calculate()`until there isn't any match that splits the question or any errors.
251+
5. One at a time, the numbers are returned from the `calculate()` calls on the stack, until the main `mul(calculate("1 plus -10"), calculate("13 divided by 2"))` is solved, at which point the answer is returned.
252252

253253
For a more visual picture, you can step through the code on [pythontutor.com][recursion-in-loop-pythontutor].
254254

0 commit comments

Comments
 (0)