Skip to content

Commit b3c2073

Browse files
committed
fixing stuff
1 parent e35f6bd commit b3c2073

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

basics/answers.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,11 @@ isn't exactly like mine but it works just fine it's ok, and you can
436436
437437
## More Classes
438438
439-
1. Delete all global variables, and use arguments and return values. We also
440-
need to handle the `len(words) == 0` case differently, and returning `None`
441-
makes sense now.
439+
1. Delete the `global` everywhere, and add arguments and return values until
440+
the code works.
441+
442+
We also need to handle the `len(words) == 0` case differently, and returning
443+
`None` makes sense now.
442444
443445
```python
444446
import random

basics/more-classes.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ for a reason. Let's look at this:
1414

1515
```python
1616
>>> stuff = 1
17-
>>> def set_stuff():
17+
>>> def thingy():
1818
... stuff = 2
1919
...
20-
>>> set_stuff()
20+
>>> thingy()
2121
>>> stuff # this did NOT change to 2
2222
1
2323
>>>
2424
```
2525

2626
The problem is that `stuff` is a
2727
[local variable](defining-functions.md#locals-and-globals) inside the
28-
`set_stuff` function. There are actually two variables called `stuff`; the
29-
local `stuff` in `set_stuff`, and the global `stuff`:
28+
`thingy` function. There are actually two variables called `stuff`; the
29+
local `stuff` in `thingy`, and the global `stuff`:
3030

3131
![Global scope: stuff = 1. Local scope inside global scope: stuff = 2.](../images/stuff-global-and-local.png)
3232

@@ -35,7 +35,7 @@ Of course, this is bad style because it's very confusing. To fix this, you
3535
see below):
3636

3737
```python
38-
def set_stuff():
38+
def thingy():
3939
global stuff
4040
stuff = 2
4141
```
@@ -233,9 +233,9 @@ def validate_user_info():
233233
try:
234234
if int(room_number) <= 0:
235235
# room_number is '0', or negative (e.g. '-2')
236-
return "room number is negative"
236+
return "room number must be positive"
237237
except ValueError:
238-
# int() failed, room_number is e.g. 'lol'
238+
# int(room_number) failed, room_number is e.g. 'lol'
239239
return "room number is not an integer"
240240

241241
if ' ' in user_name:
@@ -419,7 +419,7 @@ you can import it and try out all the things as usual, and figure out what's
419419
wrong:
420420

421421
```python
422-
>>> import userinfo
422+
>>> import userinfo # save the program to userinfo.py
423423
>>> info = userinfo.UserInfo('a', 'b', 'lol', '123-456-7890', '123-456-7890')
424424
>>> info
425425
<userinfo.UserInfo object at 0x7fd110f8ac88>

0 commit comments

Comments
 (0)