Skip to content

Commit

Permalink
Merge pull request #337 from dndln/gh-pages
Browse files Browse the repository at this point in the history
Fix issue #329
  • Loading branch information
valentina-s authored Dec 22, 2016
2 parents 030f3fb + 2f72614 commit bfc5fe9
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions _episodes/08-defensive.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,26 +472,26 @@ This violates another important rule of programming:
> ## Testing Assertions
>
> Given a sequence of values, the function `running` returns
> a list containing the running totals at each index.
> Given a sequence of a number of cars, the function `get_total_cars` returns
> the total number of cars.
>
> ~~~
> running([1, 2, 3, 4])
> get_total_cars([1, 2, 3, 4])
> ~~~
> {: .python}
>
> ~~~
> [1, 3, 6, 10]
> 10
> ~~~
> {: .output}
>
> ~~~
> running('abc')
> get_total_cars(['a', 'b', 'c'])
> ~~~
> {: .python}
>
> ~~~
> ['a', 'ab', 'abc']
> ValueError: invalid literal for int() with base 10: 'a'
> ~~~
> {: .output}
>
Expand All @@ -500,24 +500,24 @@ This violates another important rule of programming:
> give an example of input that will make that assertion fail.
>
> ~~~
> def running(values):
> def get_total(values):
> assert len(values) > 0
> result = [values[0]]
> for v in values[1:]:
> assert result[-1] >= 0
> result.append(result[-1] + v)
> assert result[-1] >= result[0]
> return result
> for element in values:
> assert int(element)
> values = [int(element) for element in values]
> total = sum(values)
> assert total > 0
> return total
> ~~~
> {: .python}
>
> > ## Solution
> > * The first assertion checks that the input sequence `values` is not empty.
> > An empty sequence such as `[]` will make it fail.
> > * The second assertion checks that the first value in the list is positive.
> > Input such as `[-1,0,2,3]` will make it fail.
> > * The third assertion checks that the running total always increases.
> > Input such as `[0,1,3,-5,4]` will make it fail.
> > * The second assertion checks that each value in the list can be turned into an integer.
> > Input such as `[1, 2,'c', 3]` will make it fail.
> > * The third assertion checks that the total of the list is greater than 0.
> > Input such as `[-10, 2, 3]` will make it fail.
> {: .solution}
{: .challenge}
Expand Down

0 comments on commit bfc5fe9

Please sign in to comment.