Skip to content

Commit 430b225

Browse files
authored
Merge pull request #54 from kcarini/patch-1
Add solutions for Episode 18
2 parents ec1df2c + f3afec5 commit 430b225

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

episodes/18-style.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ average(values)
106106
> return highest
107107
> ~~~
108108
> {: .python}
109+
> >
110+
> > ## Solution
111+
> >
112+
> > These two lines will show up in online help:
113+
> >
114+
> > ~~~
115+
> > '''Determine overall maximum edit distance.'''
116+
> > '''Avoid checking sequence against itself.'''
117+
> > ~~~
118+
> > {: .python}
119+
> >
120+
> > This line will not be made available because it is not in the docstring format: `"Find maximum edit distance between multiple sequences."` Docstrings should reside within the function definition, using three single quotes.
121+
> >
122+
> >
123+
> > There is one syntax error:
124+
> > ~~~
125+
> > Traceback (most recent call last):
126+
> > File "<interactive input>", line 1, in <module>
127+
> > File "<module2>", line 11, in overall_max
128+
> > NameError: global name 'edit_distance' is not defined
129+
> > ~~~
130+
> > {: .python}
131+
> >
132+
> > The `edit_distance` function has not been defined:
133+
> > ~~~
134+
> > this = edit_distance(left, right)
135+
> > ~~~
136+
> > {: .python}
137+
> {: .solution}
109138
{: .challenge}
110139
111140
> ## Document This
@@ -122,6 +151,32 @@ average(values)
122151
> return values[1]
123152
> ~~~
124153
> {: .python}
154+
> >
155+
> > ## Solution
156+
> >
157+
> > Change the `#` to `'''` to change to docstring:
158+
> >
159+
> > ~~~
160+
> > def middle(a, b, c):
161+
> > ''' Return the middle value of three.
162+
> > Assumes the values can actually be compared.
163+
> > '''
164+
> > values = [a, b, c]
165+
> > values.sort()
166+
> > return values[1]
167+
> > ~~~
168+
> > {: .python}
169+
> >
170+
> > Calling `help` on the `middle` function now shows the docstring:
171+
> > ~~~
172+
> > help (middle)
173+
> > Help on function middle in module __main__:
174+
> > middle(a, b, c)
175+
> > Return the middle value of three.
176+
> > Assumes the values can actually be compared.
177+
> > ~~~
178+
> > {: .python}
179+
> {: .solution}
125180
{: .challenge}
126181
127182
> ## Clean Up This Code

0 commit comments

Comments
 (0)