@@ -87,32 +87,6 @@ These are answers for exercises in the chapters. In programming, there's always
87
87
print (" Wrong username." )
88
88
```
89
89
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
-
116
90
# # Loops
117
91
118
92
1 . 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
197
171
198
172
# # Trey Hunner: zip and enumerate
199
173
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.
201
175
202
176
```py
203
177
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
238
212
```
239
213
240
214
3 . 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:
243
217
244
218
```py
245
219
uppercase = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -250,6 +224,19 @@ These are answers for exercises in the chapters. In programming, there's always
250
224
print (index, upper, lower)
251
225
```
252
226
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
+
253
240
Another alternative is to pass an `enumerate ` result to `zip ` . This is
254
241
a bit more complicated, so I wouldn' t do it this way.
255
242
0 commit comments