Skip to content

Commit 098c29f

Browse files
authored
Solution to Exercise 2
I have changed the way the labels are constructed for different alpha values in the legend. In the hint for the exercise 2 you mentioned string concatenation as well as str() function for constructing labels for different alpha values, however in the solution you used f string. So, may be it would be better to show first how string concatenation is sed and then propose f string as an alternative version.
1 parent fa442f6 commit 098c29f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lectures/python_by_example.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,17 @@ Set $T=200$ and $\alpha = 0.9$.
475475

476476
### Exercise 2
477477

478-
Starting with your solution to exercise 2, plot three simulated time series,
479-
one for each of the cases $\alpha=0$, $\alpha=0.8$ and $\alpha=0.98$.
478+
Starting with your solution to exercise 1, plot three simulated time series,
479+
one for each of the cases: $\alpha=0$, $\alpha=0.8$ and $\alpha=0.98$.
480480

481481
Use a `for` loop to step through the $\alpha$ values.
482482

483483
If you can, add a legend, to help distinguish between the three time series.
484484

485485
Hints:
486486

487-
* If you call the `plot()` function multiple times before calling `show()`, all of the lines you produce will end up on the same figure.
488-
* For the legend, noted that the expression `'foo' + str(42)` evaluates to `'foo42'`.
487+
* If you call a `plot()` function multiple times before calling a `show()`, all of the lines you produce will end up on the same figure.
488+
* For the legend, note that the expression `'foo' + str(42)` evaluates to `'foo42'`.
489489

490490
### Exercise 3
491491

@@ -578,7 +578,7 @@ for α in α_values:
578578
x[0] = 0
579579
for t in range(T):
580580
x[t+1] = α * x[t] + np.random.randn()
581-
plt.plot(x, label=f'$\\alpha = {α}$')
581+
plt.plot((x, label = 'α = ' + str(α)) or we can also use plt.plot(x, label=f'$\\alpha = {α}$')
582582
583583
plt.legend()
584584
plt.show()

0 commit comments

Comments
 (0)