You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/12-for-loops.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -237,6 +237,35 @@ print(total)
237
237
> print(result)
238
238
> ~~~
239
239
> {: .python}
240
+
> >
241
+
> > ## Solution
242
+
> >
243
+
> > `result` is an empty string because we use it to build or accumulate on our reverse string. `char` is the loop variable for `original`. Each time through the loop `char` takes on one value from `original`. Use `char` with `result` to control the order of the string. Our loop code should look like this:
244
+
> > ~~~
245
+
> > original = "tin"
246
+
> > result = ""
247
+
> > for char in original:
248
+
> > result = char + result
249
+
> > print(result)
250
+
> > nit
251
+
> > ~~~
252
+
> > If you were to expand out the loop the iterations would look something like this:
0 commit comments