Skip to content

Commit f5c9b09

Browse files
committed
Little fixes
1 parent 9db8ee7 commit f5c9b09

8 files changed

+60
-34
lines changed

answers.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
These are answers for exercises in the chapters. In programming, there's always more than one way to do things, so if your solution wasn't exactly like mine it's not necessarily wrong. Some Python users say that there should be only one right way, but that goal will never be fully reached.
44

5-
### Chapter 1
5+
## Chapter 1
66

77
1. 18996.20 €
88

@@ -53,7 +53,7 @@ These are answers for exercises in the chapters. In programming, there's always
5353
>>>
5454
```
5555

56-
### Chapter 3
56+
## Chapter 3
5757

5858
1. Content of the file:
5959

@@ -94,7 +94,7 @@ These are answers for exercises in the chapters. In programming, there's always
9494
print(words * 1000)
9595
```
9696

97-
### Chapter 4
97+
## Chapter 4
9898

9999
1. You can compare the word against an empty string (`""` or `''`). In this example, the password is "secret".
100100

@@ -153,7 +153,8 @@ These are answers for exercises in the chapters. In programming, there's always
153153
Wrong password!
154154
>>>
155155

156-
3. This is a great chance to use a while loop. In this example, the correct password is "secret".
156+
3. This is a great chance to use a while loop. In this example, the
157+
correct password is "secret".
157158

158159
```py
159160
running = True
@@ -166,15 +167,30 @@ These are answers for exercises in the chapters. In programming, there's always
166167
print("Wrong password.")
167168
```
168169

169-
Another alternative:
170+
You can also use `break` to get out of a loop, and `while True:` to
171+
do an infinite loop. This is recommended instead of the previous
172+
alternative, because you don't need a useless `running` variable.
173+
174+
```py
175+
while True:
176+
password = input("Enter your password: ")
177+
if password == "secret":
178+
print("Welcome!")
179+
break
180+
else:
181+
print("Wrong password.")
182+
```
183+
184+
Even shorter alternative:
170185

171186
```py
172187
while input("Enter your password: ") != "secret":
173188
print("Wrong password.")
174189
print("Welcome!")
175190
```
176191

177-
4. One way to do this is to put the inputs directly to `if` and `elif` lines. Again, the correct password is "secret".
192+
4. One way to do this is to put the inputs directly to `if` and `elif`
193+
lines. Again, the correct password is "secret".
178194

179195
```py
180196
if input("Enter your password: (3 attempts left) ") == "secret":
@@ -202,4 +218,8 @@ These are answers for exercises in the chapters. In programming, there's always
202218
Welcome!
203219
>>>
204220

205-
[Home](README.md)
221+
***
222+
223+
You may use this tutorial freely at your own risk. See [LICENSE](LICENSE).
224+
225+
[Back to the list of contents](README.md)

classes.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This tutorial assumes that you know how functions work and how to
99
create your own functions with the `def` keyword. If you don't, I
1010
highly recommend learning that first, and then moving to classes.
1111

12-
### Why should I use custom classes in my projects?
12+
## Why should I use custom classes in my projects?
1313

1414
Python comes with a lot of classes that you are already familiar with.
1515

@@ -61,7 +61,7 @@ Python comes with. Instead you can define a Website class, and make
6161
Websites and process information about websites directly. Defining your
6262
own object types like this is called **object-orientated programming**.
6363

64-
### First class
64+
## First class
6565

6666
In Python, `pass` does nothing.
6767

@@ -160,7 +160,7 @@ handy way to see which attributes the instance contains.
160160
>>>
161161
```
162162

163-
### Class attributes
163+
## Class attributes
164164

165165
What happens if we set an attribute of the `Website` class to some value
166166
instead of doing that to an instance?
@@ -205,7 +205,7 @@ access class attributes through instances also, so in this case
205205
confusing, which is why it's not recommended to use class attributes like
206206
this. Use instance attributes instead, e.g. `stackoverflow.is_online = True`.
207207

208-
### Functions and methods
208+
## Functions and methods
209209

210210
Let's define a function that prints information about a website.
211211

@@ -276,7 +276,7 @@ In other words, `Class.method(instance)` does the same thing as
276276
`instance.method()`. This also works with built-in classes, for
277277
example `'hello'.lower()` is same as `str.lower('hello')`.
278278

279-
### Defining methods when defining the class
279+
## Defining methods when defining the class
280280

281281
Maybe we could define a method when we make the class instead of adding
282282
it later?
@@ -362,7 +362,7 @@ Free to use: True
362362
Classes have many other magic methods too, but I'm not going to cover
363363
them in this tutorial.
364364

365-
### When should I use classes?
365+
## When should I use classes?
366366

367367
Don't do this:
368368

@@ -393,7 +393,7 @@ word = input("Enter something: ")
393393
print("You entered " + word + ".")
394394
```
395395

396-
### Important things
396+
## Important things
397397

398398
Here are some of the most important things covered in this tutorial.
399399
Make sure you understand them.
@@ -413,3 +413,9 @@ Make sure you understand them.
413413
- `__init__` is a special method, and it's ran when a new instance of a
414414
class is created. It does nothing by default.
415415
- Don't use classes if your code is easier to read without them.
416+
417+
***
418+
419+
You may use this tutorial freely at your own risk. See [LICENSE](LICENSE).
420+
421+
[Back to the list of contents](README.md)

editor-setup.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ you want to indent**. Your editor should give you four spaces when you
2020
hit the tab key. Your editor should also remove four spaces when you
2121
hit backspace and there are four spaces before the cursor.
2222

23-
#### Geany
23+
### Geany
2424

2525
1. Create a file called `hello.py`, and open it in geany. Or create a
2626
file in geany and save it as `hello.py`.
@@ -36,7 +36,7 @@ color than the rest of your text. `"Strings"`, `# comments` and
3636
everything else should also have their own colors. This makes it much
3737
easier to write code.
3838

39-
#### Geany
39+
### Geany
4040

4141
Geany has syntax highlighting by default. You can also install more
4242
[color schemes](https://www.geany.org/Download/Extras#colors) if you
@@ -47,7 +47,7 @@ View, then Change Color Scheme.
4747

4848
Advanced editors support plugins. You may find some of them useful.
4949

50-
#### Geany
50+
### Geany
5151

5252
On Debian-based GNU/Linux distributions, install the geany-plugins
5353
package. See [the Geany website](https://plugins.geany.org/) for

getting-help.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
When you have a problem with Python, you're not alone! There are many
44
places to ask for help in.
55

6-
### IRC
6+
## IRC
77

88
IRC is the oldest chatting service I know, but as of 2016, it's still
99
in use, and a great way to get help in Python. You don't need to
@@ -34,12 +34,12 @@ Do this:
3434
Don't do this:
3535

3636
<you> HEEEEELP MEEEEEEEEEEEEEEE!!!
37-
<you> File "foo", line 3
37+
<you> File "hello.py", line 3
3838
<you> if a = b:
3939
<you> ^
4040
<you> SyntaxError: invalid syntax
4141

42-
### Websites to ask help on
42+
## Websites to ask help on
4343

4444
Personally, I've never asked a question on any of these sites. Getting
4545
help on IRC is much faster.

installing-python.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Let's get started!
1010

1111
## Downloading and installing Python
1212

13-
#### Windows
13+
### Windows
1414

1515
Use the official Python installer, it will install Python and IDLE for
1616
you.
@@ -22,12 +22,12 @@ you.
2222
4. Select the "advanced installation" option, and make sure the py.exe
2323
launcher gets installed.
2424

25-
#### Mac OSX
25+
### Mac OSX
2626

2727
I don't have an up-to-date copy of Mac OSX. If you would like to write
2828
instructions for OSX, [tell me](contact-me.md).
2929

30-
#### GNU/Linux
30+
### GNU/Linux
3131

3232
You already have Python, there's no need to download anything.
3333

@@ -49,7 +49,7 @@ I'm not going to focus on the third option in this tutorial, but if you
4949
know how to use Python with something else than PowerShell, command
5050
prompt, a terminal or IDLE it's fine. Do whatever you want.
5151

52-
#### If you are not an advanced user and you have no idea what PowerShell, command prompt and terminal are
52+
### If you are not an advanced user and you have no idea what PowerShell, command prompt and terminal are
5353

5454
Use IDLE. Experienced Python users will say that IDLE is garbage, but
5555
don't listen to them. These people want you to use "better"
@@ -74,7 +74,7 @@ take more screenshots:
7474
The exact content of your Python's welcome message is probably different
7575
than mine, it's ok.
7676

77-
#### If you like working with PowerShell, command prompt or terminal
77+
### If you like working with PowerShell, command prompt or terminal
7878

7979
On Windows. you should be able to run Python from a PowerShell window,
8080
or a command prompt window if you don't have PowerShell. Open one of

the-way-of-the-program.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ boring.
1010
When you're done reading, read the summary and make sure you've learned
1111
everything.
1212

13-
### Summary
13+
## Summary
1414

1515
- Now you should have some kind of idea about what programming is.
1616
- Each value has a type, and you can find that out with `type(value)`.

using-functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 3. Using functions and storing code in files
22

3-
### Functions
3+
## Functions
44

55
Now we know how to make Python show text.
66

@@ -103,7 +103,7 @@ Enter something: hello
103103
>>>
104104
```
105105

106-
### Storing code in files
106+
## Storing code in files
107107

108108
Now it's time to write some code into a file for the first time. In IDLE, go to File at top left and select New File, or just press Ctrl+N.
109109

@@ -136,7 +136,7 @@ After running the program you can check what the `word` variable contains in the
136136
>>>
137137
```
138138

139-
### Exercises
139+
## Exercises
140140

141141
1. Write a program into a file that asks the user to write a word and then prints that word 1000 times. For example, if the user enters `hi` the program would reply `hihihihi...`.
142142
2. Make it to print spaces between the words. It should be like `hi hi hi hi...`.

variables.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 2. Variables, Booleans and None
22

3-
### Variables
3+
## Variables
44

55
Variables are easy to understand. They simply **contain data**. Actually
66
they [point to data](https://www.youtube.com/watch?v=_AEJHKGk9ns), but
@@ -109,7 +109,7 @@ variable called hello and then type hello:
109109
>>>
110110
```
111111

112-
### Booleans
112+
## Booleans
113113

114114
There are two Boolean values, True and False. In Python, and in many
115115
other programming languages, `=` is assigning and `==` is comparing.
@@ -142,7 +142,7 @@ False
142142
>>>
143143
```
144144

145-
### None
145+
## None
146146

147147
None is Python's "nothing" value. It behaves just like any other value,
148148
and it's often used as a default value for different kinds of things.
@@ -164,7 +164,7 @@ This is because the prompt never echoes back None. That is handy,
164164
because many things result in None, and it would be annoying to see
165165
None coming up all the time.
166166

167-
### Other comparing operators
167+
## Other comparing operators
168168

169169
So far we've used `==`, but there are other operators also. At this
170170
point, this list probably looks awfully long, but it's actually pretty
@@ -191,7 +191,7 @@ However, `!=` and `not in` should be used in cases like this because
191191
they're more convinient once you get used to them.
192192

193193
There's also `is`, but don't use it instead of `==` unless you know
194-
what you are doing. We'll find uses for it later.
194+
what you are doing. We'll learn more about it later.
195195

196196
***
197197

0 commit comments

Comments
 (0)