@@ -472,26 +472,26 @@ This violates another important rule of programming:
472472
473473> ## Testing Assertions
474474>
475- > Given a sequence of values, the function `running ` returns
476- > a list containing the running totals at each index .
475+ > Given a sequence of values, the function `get_total ` returns
476+ > the total of the sequence .
477477>
478478> ~~~
479- > running ([1, 2, 3, 4])
479+ > get_total ([1, 2, 3, 4])
480480> ~~~
481481> {: .python}
482482>
483483> ~~~
484- > [1, 3, 6, 10]
484+ > 10
485485> ~~~
486486> {: .output}
487487>
488488> ~~~
489- > running('abc' )
489+ > get_total(['a', 'b', 'c'] )
490490> ~~~
491491> {: .python}
492492>
493493> ~~~
494- > ['a', 'ab', 'abc']
494+ > ValueError: invalid literal for int() with base 10: 'a'
495495> ~~~
496496> {: .output}
497497>
@@ -500,24 +500,24 @@ This violates another important rule of programming:
500500> give an example of input that will make that assertion fail.
501501>
502502> ~~~
503- > def running (values):
503+ > def get_total (values):
504504> assert len(values) > 0
505- > result = [ values[0]]
506- > for v in values[1:]:
507- > assert result[-1] >= 0
508- > result.append(result[-1] + v )
509- > assert result[-1] >= result[0]
510- > return result
505+ > for element in values:
506+ > assert int(element)
507+ > values = [int(element) for element in values]
508+ > total = sum(values )
509+ > assert total > 0
510+ > return total
511511> ~~~
512512> {: .python}
513513>
514514> > ## Solution
515515> > * The first assertion checks that the input sequence `values` is not empty.
516516> > An empty sequence such as `[]` will make it fail.
517- > > * The second assertion checks that the first value in the list is positive .
518- > > Input such as `[-1,0,2, 3]` will make it fail.
519- > > * The third assertion checks that the running total always increases .
520- > > Input such as `[0,1,3,-5,4 ]` will make it fail.
517+ > > * The second assertion checks that each value in the list can be turned into an integer .
518+ > > Input such as `[1, 2,'c', 3]` will make it fail.
519+ > > * The third assertion checks that the total of the list is greater than 0 .
520+ > > Input such as `[-10, 2, 3 ]` will make it fail.
521521> {: .solution}
522522{: .challenge}
523523
0 commit comments