Skip to content

Commit 744ba11

Browse files
committed
clean up stuff
1 parent eb34d9a commit 744ba11

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

answers.md

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

11892
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
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

240214
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:
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

if.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,32 @@ else:
275275
5. Make a program that asks for username and password and checks them.
276276
Make users "foo" and "bar" with passwords "biz" and "baz".
277277

278+
Example output:
279+
280+
```
281+
>>> ================================ RESTART ================================
282+
>>>
283+
Enter your username: foo
284+
Enter your password: biz
285+
Welcome foo!
286+
>>> ================================ RESTART ================================
287+
>>>
288+
Enter your username: bar
289+
Enter your password: baz
290+
Welcome bar!
291+
>>> ================================ RESTART ================================
292+
>>>
293+
Enter your username: spam
294+
Enter your password: eggs
295+
Wrong username.
296+
>>> ================================ RESTART ================================
297+
>>>
298+
Enter your username: foo
299+
Enter your password: lol
300+
Wrong password!
301+
>>>
302+
```
303+
278304
The answers are [here](answers.md).
279305
280306
***

0 commit comments

Comments
 (0)