@@ -14,19 +14,19 @@ for a reason. Let's look at this:
14
14
15
15
``` python
16
16
>> > stuff = 1
17
- >> > def set_stuff ():
17
+ >> > def thingy ():
18
18
... stuff = 2
19
19
...
20
- >> > set_stuff ()
20
+ >> > thingy ()
21
21
>> > stuff # this did NOT change to 2
22
22
1
23
23
>> >
24
24
```
25
25
26
26
The problem is that ` stuff ` is a
27
27
[ 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 ` :
30
30
31
31
![ Global scope: stuff = 1. Local scope inside global scope: stuff = 2.] ( ../images/stuff-global-and-local.png )
32
32
@@ -35,7 +35,7 @@ Of course, this is bad style because it's very confusing. To fix this, you
35
35
see below):
36
36
37
37
``` python
38
- def set_stuff ():
38
+ def thingy ():
39
39
global stuff
40
40
stuff = 2
41
41
```
@@ -233,9 +233,9 @@ def validate_user_info():
233
233
try :
234
234
if int (room_number) <= 0 :
235
235
# room_number is '0', or negative (e.g. '-2')
236
- return " room number is negative "
236
+ return " room number must be positive "
237
237
except ValueError :
238
- # int() failed, room_number is e.g. 'lol'
238
+ # int(room_number ) failed, room_number is e.g. 'lol'
239
239
return " room number is not an integer"
240
240
241
241
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
419
419
wrong:
420
420
421
421
```python
422
- >> > import userinfo
422
+ >> > import userinfo # save the program to userinfo.py
423
423
>> > info = userinfo.UserInfo(' a' , ' b' , ' lol' , ' 123-456-7890' , ' 123-456-7890' )
424
424
>> > info
425
425
< userinfo.UserInfo object at 0x 7fd110f8ac88>
0 commit comments