From cc83915509d24881f4298e9cace8fc72401fd1c8 Mon Sep 17 00:00:00 2001 From: Stephen Pearce <36123293+sparce@users.noreply.github.com> Date: Tue, 12 Nov 2019 01:40:09 +1100 Subject: [PATCH] 02-loop.md: Update loop variable names (#738) --- _episodes/02-loop.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/_episodes/02-loop.md b/_episodes/02-loop.md index 49ddfdf..9145c99 100644 --- a/_episodes/02-loop.md +++ b/_episodes/02-loop.md @@ -285,8 +285,8 @@ so we should always use it when we can. > > > ## Solution > > ~~~ -> > for i in range(1, 4): -> > print(i) +> > for number in range(1, 4): +> > print(number) > > ~~~ > > {: .language-python} > {: .solution} @@ -341,7 +341,7 @@ so we should always use it when we can. > > ## Solution > > ~~~ > > result = 1 -> > for i in range(0, 3): +> > for number in range(0, 3): > > result = result * 5 > > print(result) > > ~~~ @@ -375,12 +375,12 @@ so we should always use it when we can. > (0, 1, 2,...) and the value from the original sequence: > > ~~~ -> for i, x in enumerate(xs): -> # Do something using i and x +> for idx, val in enumerate(a_list): +> # Do something using idx and val > ~~~ > {: .language-python} > -> The code above loops through `xs`, assigning the index to `i` and the value to `x`. +> The code above loops through `a_list`, assigning the index to `idx` and the value to `val`. > > Suppose you have encoded a polynomial as a list of coefficients in > the following way: the first element is the constant term, the @@ -389,24 +389,24 @@ so we should always use it when we can. > > ~~~ > x = 5 -> cc = [2, 4, 3] +> coefs = [2, 4, 3] > ~~~ > {: .language-python} > > ~~~ -> y = cc[0] * x**0 + cc[1] * x**1 + cc[2] * x**2 +> y = coefs[0] * x**0 + coefs[1] * x**1 + coefs[2] * x**2 > y = 97 > ~~~ > {: .output} > -> Write a loop using `enumerate(cc)` which computes the value `y` of any -> polynomial, given `x` and `cc`. +> Write a loop using `enumerate(coefs)` which computes the value `y` of any +> polynomial, given `x` and `coefs`. > > > ## Solution > > ~~~ > > y = 0 -> > for i, c in enumerate(cc): -> > y = y + x**i * c +> > for idx, coef in enumerate(coefs): +> > y = y + coef * x**idx > > ~~~ > > {: .language-python} > {: .solution} -- GitLab