Skip to content

Commit 9164859

Browse files
committed
fix syntax highlighting and typos
1 parent 81f7a0f commit 9164859

File tree

3 files changed

+50
-58
lines changed

3 files changed

+50
-58
lines changed

answers.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ These are answers for exercises in the chapters. In programming, there's always
116116

117117
```py
118118
users = [
119-
['foo', 'bar'],
120-
['biz', 'baz'],
119+
['foo', 'biz'],
120+
['bar', 'baz'],
121121
]
122122

123123
username = input("Username: ")
@@ -140,8 +140,8 @@ These are answers for exercises in the chapters. In programming, there's always
140140

141141
```py
142142
users = [
143-
['foo', 'bar'],
144-
['biz', 'baz'],
143+
['foo', 'biz'],
144+
['bar', 'baz'],
145145
]
146146

147147
while True:
@@ -165,14 +165,14 @@ These are answers for exercises in the chapters. In programming, there's always
165165

166166
```py
167167
users = [
168-
['foo', 'bar'],
169-
['biz', 'baz'],
168+
['foo', 'biz'],
169+
['bar', 'baz'],
170170
]
171171

172172
for attempts_left in [3, 2, 1, 0]:
173173
if attempts_left == 0:
174174
print("No attempts left!")
175-
break
175+
break # break the outer for loop
176176

177177
print(attempts_left, "attempts left.")
178178
username = input("Username: ")

if.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ else:
230230
if the code under the if statement does not run.
231231
- elif is short for else if.
232232

233-
## Excercises
233+
## Exercises
234234

235235
1. Write a program into a file that asks the user to write a word and
236236
then prints that word 1000 times. For example, if the user enters

loops.md

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,22 @@ print("It's not raining anymore.")
3232
If you're not familiar with while loops, the program's output may be a
3333
bit surprising:
3434

35-
```
36-
Oh crap, it's raining!
37-
Oh crap, it's raining!
38-
Oh crap, it's raining!
39-
Oh crap, it's raining!
40-
Oh crap, it's raining!
41-
Oh crap, it's raining!
42-
Oh crap, it's raining!
43-
Oh crap, it's raining!
44-
Oh crap, it's raining!
45-
Oh crap, it's raining!
46-
Oh crap, it's raining!
47-
Oh crap, it's raining!
48-
Oh crap, it's raining!
49-
Oh crap, it's raining!
50-
Oh crap, it's raining!
51-
(much more raining)
52-
```
35+
Oh crap, it's raining!
36+
Oh crap, it's raining!
37+
Oh crap, it's raining!
38+
Oh crap, it's raining!
39+
Oh crap, it's raining!
40+
Oh crap, it's raining!
41+
Oh crap, it's raining!
42+
Oh crap, it's raining!
43+
Oh crap, it's raining!
44+
Oh crap, it's raining!
45+
Oh crap, it's raining!
46+
Oh crap, it's raining!
47+
Oh crap, it's raining!
48+
Oh crap, it's raining!
49+
Oh crap, it's raining!
50+
(much more raining)
5351

5452
Again, this program does not break your computer. It just prints the
5553
same thing multiple times. We can interrupt it by pressing Ctrl+C.
@@ -76,17 +74,15 @@ print("It's not raining anymore.")
7674

7775
Running the program may look like this:
7876

79-
```
80-
It's raining!
81-
Or is it? (y=yes, n=no) i dunno
82-
Enter y or n next time.
83-
It's raining!
84-
Or is it? (y=yes, n=no) y
85-
Oh well...
86-
It's raining!
87-
Or is it? (y=yes, n=no) n
88-
It's not raining anymore.
89-
```
77+
It's raining!
78+
Or is it? (y=yes, n=no) i dunno
79+
Enter y or n next time.
80+
It's raining!
81+
Or is it? (y=yes, n=no) y
82+
Oh well...
83+
It's raining!
84+
Or is it? (y=yes, n=no) n
85+
It's not raining anymore.
9086

9187
We can also interrupt a loop even if the condition is still true using
9288
the `break` keyword. In this case, we'll set condition to True and rely
@@ -106,14 +102,12 @@ while True:
106102

107103
The program works like this:
108104

109-
```py
110-
Is it raining? (y=yes, n=no) who knows
111-
Enter y or n.
112-
Is it raining? (y=yes, n=no) y
113-
It's raining!
114-
Is it raining? (y=yes, n=no) n
115-
It's not raining anymore.
116-
```
105+
Is it raining? (y=yes, n=no) who knows
106+
Enter y or n.
107+
Is it raining? (y=yes, n=no) y
108+
It's raining!
109+
Is it raining? (y=yes, n=no) n
110+
It's not raining anymore.
117111

118112
## Until loops
119113

@@ -146,13 +140,11 @@ print(stuff[4])
146140

147141
The output of the program is like this:
148142

149-
```py
150-
hello
151-
hi
152-
how are you doing
153-
im fine
154-
how about you
155-
```
143+
hello
144+
hi
145+
how are you doing
146+
im fine
147+
how about you
156148

157149
But this is only going to print five items, so if we add something to
158150
stuff, it's not going to be printed. Or if we remove something from
@@ -161,7 +153,8 @@ stuff, we'll get an error saying "list index out of range".
161153
We could also create an index variable, and use a while loop:
162154

163155
```py
164-
>>> length_of_stuff = len(stuff) # len(x) is the length of x
156+
>>> stuff = ['hello', 'hi', 'how are you doing', 'im fine', 'how about you']
157+
>>> length_of_stuff = len(stuff) # len(x) is the length of x, 5 in this case
165158
>>> index = 0
166159
>>> while index < length_of_stuff:
167160
... print(stuff[index])
@@ -181,7 +174,6 @@ a lot of stuff to worry about for just printing each item.
181174
This is when for loops come in:
182175

183176
```py
184-
>>> stuff = ['hello', 'hi', 'how are you doing', 'im fine', 'how about you']
185177
>>> for thing in stuff:
186178
... # this is repeated for each element of stuff, that is, first
187179
... # for stuff[0], then for stuff[1], etc.
@@ -236,7 +228,7 @@ Instead, you can create a copy of stuff and loop over it.
236228
>>>
237229
```
238230

239-
Or if you want to clear a list, just use the `.clear()` list method.
231+
Or if you want to clear a list, just use the `.clear()` list method:
240232

241233
```py
242234
>>> stuff = ['hello', 'hi', 'how are you doing', 'im fine', 'how about you']
@@ -246,7 +238,7 @@ Or if you want to clear a list, just use the `.clear()` list method.
246238
>>>
247239
```
248240

249-
## Excercises
241+
## Exercises
250242

251243
1. Back in "Using if, else and elif" we created a program that asked
252244
for username and password and checks them, and we made users "foo"
@@ -256,8 +248,8 @@ Or if you want to clear a list, just use the `.clear()` list method.
256248

257249
```py
258250
users = [
259-
['foo', 'bar'],
260-
['biz', 'baz'],
251+
['foo', 'biz'],
252+
['bar', 'baz'],
261253
]
262254
```
263255

0 commit comments

Comments
 (0)