Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Jan 5, 2018
1 parent bcec00e commit 60c2d78
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
12 changes: 6 additions & 6 deletions basics/answers.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ isn't exactly like mine but it works just fine it's ok, and you can
```python
no_space = input("Enter a word: ")
yes_space = no_space + " "
print(yes_space * 999 + no_space)
print(yes_space*999 + no_space)
```

5. Like this:
Expand All @@ -79,21 +79,20 @@ isn't exactly like mine but it works just fine it's ok, and you can
```

6. We can compare the word against an empty string (`""` or `''`) to
check if it's empty. In this example, the password is "s3cr3t".
check if it's empty. In this example, the password is "seKr3t".

```python
word = input("Enter your password: ")

if word == "s3cr3t":
if word == "seKr3t":
print("Welcome!")
elif word == "":
print("You didn't enter anything.")
else:
print("Access denied.")
```

This is not a good way to ask a password from the user because the
password isn't hidden in any way, but this is just an example.
Again, this is not a good way to ask a real password from the user.

## Handy stuff: Strings

Expand Down Expand Up @@ -219,7 +218,8 @@ isn't exactly like mine but it works just fine it's ok, and you can
problems and solutions:

- `namelist` is None. It should be `namelist.extend('theelous3')`,
not `namelist = namelist.extend('theelous3')`.
not `namelist = namelist.extend('theelous3')`. See [this
thing](using-functions.md#return-values).
- Now the namelist is like `['wub_wub', ..., 't', 'h', 'e', 'e', ...]`.
Python treated `'theelous3'` like a list so it added each of its
characters to `namelist`. We can use `namelist.append('theelous3')`
Expand Down
22 changes: 7 additions & 15 deletions basics/defining-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,16 @@ However, modifying a global variable in-place from a function is easy.
>>>
```

This doesn't work if the value is of an immutable type, like string or
integer because immutable values cannot be modified in-place.
Fortunately, Python will tell us if something's wrong.
This only works for changing in-place, we cannot assign a new value to
the variable.

```python
>>> thing = 1
>>> def stuff():
... thing += 1
>>> def set_stuff_to_something_new():
... stuff = ['more local stuff']
...
>>> stuff()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in stuff
UnboundLocalError: local variable 'thing' referenced before assignment
>>> set_stuff_to_something_new()
>>> stuff
['global stuff', 'local stuff']
>>>
```

Expand Down Expand Up @@ -262,10 +258,6 @@ This function can be called in two ways:
because `message = "hi"` and `some_function(message="hi")` do two
completely different things.

Personally, I would use this function with a positional argument. It
only takes one argument, so I don't need to worry about which argument
is which.

Now it's time to solve our box printing problem:

```python
Expand Down
2 changes: 1 addition & 1 deletion getting-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ places to ask for help in.

## IRC

IRC is the oldest chatting service I know, but as of 2017, it's still
IRC is the oldest chatting service I know, but as of 2018, it's still
in use, and a great way to get help in Python. You don't need to
register anywhere, just click one of the links below and you're good to
go.
Expand Down

0 comments on commit 60c2d78

Please sign in to comment.