@@ -87,32 +87,6 @@ These are answers for exercises in the chapters. In programming, there's always
8787 print (" Wrong username." )
8888 ```
8989
90- Example output:
91-
92- ```
93- >> > ================================ RESTART ================================
94- >> >
95- Enter your username: foo
96- Enter your password: biz
97- Welcome foo!
98- >> > ================================ RESTART ================================
99- >> >
100- Enter your username: bar
101- Enter your password: baz
102- Welcome bar!
103- >> > ================================ RESTART ================================
104- >> >
105- Enter your username: spam
106- Enter your password: eggs
107- Wrong username.
108- >> > ================================ RESTART ================================
109- >> >
110- Enter your username: foo
111- Enter your password: lol
112- Wrong password!
113- >> >
114- ```
115-
11690# # Loops
11791
118921 . For loop over the users, each user is a list that contains a
@@ -197,7 +171,7 @@ These are answers for exercises in the chapters. In programming, there's always
197171
198172# # Trey Hunner: zip and enumerate
199173
200- 1 . Read some lines with `input ` and then enumerate it.
174+ 1 . Read some lines with `input ` into a list and then enumerate it.
201175
202176 ```py
203177 print (" Enter something, and press Enter without typing anything" ,
@@ -238,8 +212,8 @@ These are answers for exercises in the chapters. In programming, there's always
238212 ```
239213
2402143 . This one is a bit more difficult than the other two because we
241- need to combine `zip ` and `enumerate ` . I would pass a ` zip `
242- result to `enumerate ` , like this:
215+ need to combine `zip ` and `enumerate ` . One way to do this is
216+ to pass a ` zip ` result to `enumerate ` , like this:
243217
244218 ```py
245219 uppercase = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -250,6 +224,19 @@ These are answers for exercises in the chapters. In programming, there's always
250224 print (index, upper, lower)
251225 ```
252226
227+ We can also save the zip result to a variable. I would
228+ probably do this.
229+
230+ ```py
231+ uppercase = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
232+ lowercase = ' abcdefghijklmnopqrstuvwxyz'
233+
234+ letterzip = zip (uppercase, lowercase)
235+ for index, letterpair in enumerate (letterzip, start = 1 ):
236+ upper, lower = letterpair
237+ print (index, upper, lower)
238+ ```
239+
253240 Another alternative is to pass an `enumerate ` result to `zip ` . This is
254241 a bit more complicated, so I wouldn' t do it this way.
255242
0 commit comments