Skip to content

Commit 11d9feb

Browse files
committed
Add solution to cumulative sum problem
1 parent 88313fa commit 11d9feb

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ _site
88
.Rproj.user
99
.Rhistory
1010
.RData
11-
11+
.jekyll-cache
12+
.ruby-version

_episodes/12-for-loops.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ print(total)
206206
>
207207
> > ## Solution
208208
> >
209-
> >It is a syntax error. The problem has to do with the placement of the code, not its logic.
210-
>
211-
>{: .solution}{: .challenge}
209+
> > It is a syntax error. The problem has to do with the placement of the code, not its logic.
210+
> >
211+
> {: .solution}
212+
{: .challenge}
212213

213214

214215
> ## Tracing Execution
@@ -324,6 +325,23 @@ print(total)
324325
> data = [1,2,2,5]
325326
> ~~~
326327
> {: .python}
328+
> >
329+
> > ## Solution
330+
> > ~~~
331+
> > data = [1,2,2,5]
332+
> > cumulative = []
333+
> > sum = 0
334+
> > for number in data:
335+
> > sum += number
336+
> > cumulative += [sum]
337+
> > print(cumulative)
338+
> > ~~~
339+
> > {: .python}
340+
> > ~~~
341+
> > [1, 3, 5, 10]
342+
> > ~~~
343+
> > {: .output}
344+
> {: .solution}
327345
{: .challenge}
328346
329347
> ## Identifying Variable Name Errors
@@ -332,7 +350,7 @@ print(total)
332350
> *without* running it.
333351
> 2. Run the code and read the error message.
334352
> What type of `NameError` do you think this is?
335-
> Is it a string with no quotes, a misspelled variable, or a
353+
> Is it a string with no quotes, a misspelled variable, or a
336354
> variable that should have been defined but was not?
337355
> 3. Fix the error.
338356
> 4. Repeat steps 2 and 3, until you have fixed all the errors.

0 commit comments

Comments
 (0)