Skip to content

Commit 08885b2

Browse files
committed
getting rid of IDLE and other junk
1 parent e49dfb2 commit 08885b2

File tree

6 files changed

+72
-209
lines changed

6 files changed

+72
-209
lines changed

basics/editor-setup.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ you need to keep in mind when reading the rest of this tutorial:
223223
but code in a file does nothing to the result. For example, typing
224224
`1 + 2` to the `>>>` prompt makes it echo `3`, but we need to do
225225
`print(1 + 2)` if we want to do the same thing in a file.
226+
- The editor doesn't replace the `>>>` prompt. The prompt is good for
227+
trying things out quickly, and the editor is better when we want to
228+
write longer programs.
226229

227230
## You're done!
228231

basics/getting-started.md

Lines changed: 32 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,11 @@ We didn't get an error... but `(3, 14)` is not at all what we expected!
5858
So from now on, let's use a dot with decimal numbers, because `3.14`
5959
worked just fine. Later we'll learn what `(3, 14)` is.
6060

61-
What if we type a `#`?
62-
63-
```python
64-
>>> #
65-
>>>
66-
```
67-
68-
Nothing happened at all. Maybe we can type a `#` and then some text
69-
after it?
70-
71-
```python
72-
>>> # hello there
73-
>>>
74-
```
75-
76-
Again, nothing happened.
77-
78-
If you're not using IDLE, the prompt will change from `>>>` to
79-
`...`. Just press Enter again to get it back to `>>>`.
80-
81-
```python
82-
>>> # hello again
83-
...
84-
>>>
85-
```
86-
87-
In Python, these pieces of text starting with a `#` are known as
88-
**comments**. They don't change how the code works in any way, but
89-
we can use them to explain what our code does.
90-
9161
## Using Python as a calculator
9262

93-
Maybe we could type mathematical statements?
63+
**WARNING:** This part contains boring math. Be careful!
64+
65+
Let's type some math stuff into Python and see what it does.
9466

9567
```python
9668
>>> 17 + 3
@@ -106,19 +78,22 @@ Maybe we could type mathematical statements?
10678

10779
It's working, Python just calculates the result and echoes it back.
10880

109-
The spaces between numbers and operators don't affect anything, they
110-
just make the code easier to read when they are used correctly.
81+
I added a space on both sides of `+`, `-`, `*` and `/`. Everything would
82+
work without those spaces too:
11183

11284
```python
113-
>>> 14 + 2 + 1
114-
17
115-
>>> 14 +2+ 1
116-
17
85+
>>> 4 + 2 + 1
86+
7
87+
>>> 4+2+1
88+
7
11789
>>>
11890
```
11991

120-
The evaluation order is similar to math. The parentheses `(` and `)`
121-
also work the same way.
92+
However, I recommend always adding the spaces because they make the code
93+
easier to read.
94+
95+
Things are calculated in the same order as in math. The parentheses `(`
96+
and `)` also work the same way.
12297

12398
```python
12499
>>> 1 + 2 * 3 # 2 * 3 is calculated first
@@ -128,78 +103,33 @@ also work the same way.
128103
>>>
129104
```
130105

131-
Square brackets `[]` and curly brackets `{}` cannot be used to change
132-
the evaluation order. We'll learn more about what they do later.
106+
Python also supports many other kinds of calculations, but most of the
107+
time you don't need them. Actually you don't need even these
108+
calculations most of the time, but these calculations are probably
109+
enough when you need to calculate something.
133110

134-
```python
135-
>>> [1 + 2] * 3
136-
[3, 3, 3]
137-
>>> {1 + 2} * 3
138-
Traceback (most recent call last):
139-
File "<stdin>", line 1, in <module>
140-
TypeError: unsupported operand type(s) for *: 'set' and 'int'
141-
>>>
142-
```
143-
144-
## More advanced math
145-
146-
I decided to include this in my tutorial because some people might be
147-
interested in this. Feel free to [skip this](#summary) if you're not
148-
interested.
111+
## Comments
149112

150-
The `//` operator will divide and then throw away the dot and everything
151-
after it. For example, `17 / 3` is `5.666666666666667`, and so `17 // 3`
152-
is `5` because we throw away the `.666666666666667` part.
113+
We can also type a `#` and then whatever we want after that. These bits
114+
of text are known as **comments**, and we'll find uses for them later.
153115

154116
```python
155-
>>> 17 / 3
156-
5.666666666666667
157-
>>> 17 // 3
158-
5
117+
>>> 1 + 2 # can you guess what the result is?
118+
3
159119
>>>
160120
```
161121

162-
The `%` operator gets the division remainder.
122+
Again, I put a space after the `#` and multiple spaces before it just to
123+
make things easier to read.
163124

164-
```python
165-
>>> 17 % 3
166-
2
167-
>>>
168-
```
169-
170-
For example, if there were 17 apples that should be given evenly to 3
171-
people, everyone would get 5 apples and there would be 2 apples left
172-
over.
125+
If we write comment on a line with no code on it, the prompt changes
126+
from `>>>` to `...`. To be honest, I have no idea why it does that and I
127+
think it would be better if it would just stay as `>>>`. The prompt goes
128+
back to `>>>` when we press Enter again.
173129

174130
```python
175-
>>> 17 // 3
176-
5
177-
>>> 17 % 3
178-
2
179-
>>>
180-
```
181-
182-
This is also useful for converting time from minutes to seconds. 500
183-
seconds is 8 minutes and 20 seconds.
184-
185-
```python
186-
>>> 500 // 60
187-
8
188-
>>> 500 % 60
189-
20
190-
>>>
191-
```
192-
193-
`**` can be used to raise to a power, so 3² in math is `3**2` in Python.
194-
Powers are calculated before `*` and `/`, but after `()`.
195-
196-
```python
197-
>>> 2 ** 3
198-
8
199-
>>> 2 * 3 ** 2 # 3 ** 2 is calculated first
200-
18
201-
>>> (2 * 3) ** 2 # 2 * 3 is calculated first
202-
36
131+
>>> # hello there
132+
...
203133
>>>
204134
```
205135

@@ -208,8 +138,8 @@ Powers are calculated before `*` and `/`, but after `()`.
208138
- Errors don't matter.
209139
- We can enter any Python commands to the interactive `>>>` prompt, and
210140
it will echo back the result.
211-
- Pieces of text starting with a `#` are comments.
212141
- `+`, `-`, `*` and `/` work in Python just like in math.
142+
- Pieces of text starting with a `#` are comments.
213143

214144
***
215145

basics/if.md

Lines changed: 22 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,6 @@ An important thing to notice is that the line with a print is
4040
**indented**. You can press the tab key, or if it doesn't work
4141
just press space a few times.
4242

43-
IDLE does this a bit differently, so if you use IDLE, running the
44-
example code looks more like this:
45-
46-
```python
47-
>>> its_raining = True
48-
>>> if its_raining:
49-
print("It's raining!")
50-
51-
52-
It's raining!
53-
>>>
54-
```
55-
5643
But why is that `if its_raining` instead of `if(its_raining)`?
5744

5845
Earlier we learned that `if` is a **keyword**.
@@ -66,12 +53,12 @@ SyntaxError: invalid syntax
6653
>>>
6754
```
6855

69-
**Functions** like `print` need `()` after their name to work. But `if` is
70-
a keyword, not a function, so it doesn't need `()`. Python has separate
71-
functions and keywords because it's possible to create custom functions,
72-
but it's not possible to create custom keywords. That's why keywords are
73-
usually used for "magic" things that would be difficult to do with just
74-
functions.
56+
**Functions** like `print` need `()` after their name to work. But `if`
57+
is **a keyword**, not a function, so it doesn't need `()`. Python has
58+
separate functions and keywords because it's possible to create custom
59+
functions, but it's not possible to create custom keywords. That's why
60+
keywords are usually used for "magic" things that would be difficult to
61+
do with just functions.
7562

7663
Also note that if statements check the condition once only, so if we
7764
set it to false later the if statement won't notice it.
@@ -86,62 +73,6 @@ It's not raining, but this runs anyway.
8673
>>>
8774
```
8875

89-
## Storing code in files
90-
91-
At this point it's easier to put our code into a file and use it
92-
there. If you use IDLE, go to File at top left and select New File, or
93-
just press Ctrl+N.
94-
95-
![New File in IDLE](../images/idle-new.png)
96-
97-
If you don't use IDLE, please take the time to
98-
[set up your editor correctly](../editor-setup.md). When you're done your
99-
editor should give you four spaces every time you press tab.
100-
101-
Create a file called `rain.py`, and type the following content into it:
102-
103-
```python
104-
its_raining = True
105-
if its_raining:
106-
print("It's raining!")
107-
```
108-
109-
You can save the file anywhere you want, for example on your desktop.
110-
Give it a name that ends with `.py`, for example `rain.py`. The `.py`
111-
is short for Python.
112-
113-
Now we can run the rain program. Most editors (including IDLE) will
114-
run our code when we press F5. If your editor doesn't, run it from
115-
PowerShell, command prompt or terminal. You probably need to first go
116-
to wherever you saved your file with `cd`. For example, if the file is
117-
on your desktop, type `cd Desktop` before running the file.
118-
119-
Running from IDLE looks like this:
120-
121-
>>>
122-
========================= RESTART: /some/place/rain.py =========================
123-
It's raining!
124-
>>>
125-
126-
And running from the Windows PowerShell or command prompt looks like
127-
this:
128-
129-
C:\Users\You> cd Desktop
130-
C:\Users\You\Desktop> py rain.py
131-
It's raining!
132-
C:\Users\You\Desktop>
133-
134-
Running from a terminal looks like this:
135-
136-
you@YourComputer:~$ cd Desktop
137-
you@YourComputer:~/Desktop$ python3 rain.py
138-
It's raining!
139-
you@YourComputer:~/Desktop$
140-
141-
From now on, **if a code example starts with `>>>` run it on the
142-
interactive prompt, and if it doesn't, write it to a file and run the
143-
file**.
144-
14576
## Using else
14677

14778
What if we want to print a different message if it's not raining? We
@@ -157,6 +88,9 @@ if its_not_raining:
15788
print("It's not raining.")
15889
```
15990

91+
Note that this code example doesn't start with `>>>`, so you should
92+
[save it to a file and run the file](editor-setup.md).
93+
16094
Now our program will print a different value depending on what the
16195
value of `its_raining` is.
16296

@@ -208,19 +142,19 @@ else:
208142
print("Access denied.")
209143
```
210144

211-
The program prints different things depending on what we enter.
212-
213-
>>> ================================ RESTART ================================
214-
>>>
215-
Hello!
216-
Enter your password: secret
217-
Welcome!
218-
>>> ================================ RESTART ================================
219-
>>>
220-
Hello!
221-
Enter your password: lol
222-
Access denied.
223-
>>>
145+
The program prints different things depending on what we enter:
146+
147+
```
148+
Hello!
149+
Enter your password: secret
150+
Welcome!
151+
```
152+
153+
```
154+
Hello!
155+
Enter your password: lol
156+
Access denied.
157+
```
224158

225159
Using the input function for passwords doesn't work very well because
226160
we can't hide the password with asterisks. There are better ways to get

basics/installing-python.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ Let's get started!
1818

1919
### Windows
2020

21-
Use the official Python installer, it will install Python and IDLE for
22-
you.
21+
Installing Python on Windows is a lot like installing any other program.
2322

2423
1. Go to [the official Python website](https://www.python.org/).
2524
2. Move your mouse over the blue Downloads button, but don't click it.

basics/modules.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ AttributeError: 'module' object has no attribute 'randint'
7676

7777
But what was that? Why didn't it work?
7878

79+
**TODO:** update the `-i` instructions.
80+
7981
Let's go ahead and check what's wrong. If you don't use IDLE, you'll
8082
need to pass the `-i` option to Python, so if you would normally run
81-
`python3 random.py` you should now do `python3 -i random.py`. This
82-
will run the file and then give you a `>>>` prompt that we can use
83-
to check what's wrong. If you use IDLE, just run the file normally.
83+
`python3 random.py` you should now do `python3 -i random.py`. This will
84+
run the file and then give you a `>>>` prompt that we can use to check
85+
what's wrong. If you use IDLE, just run the file normally.
8486

8587
We should end up with the same error message, and then a `>>>`.
8688
Like this:
@@ -211,12 +213,11 @@ The module name "sys" is short for "system", and it contains things
211213
that are built into Python. The official documentation is
212214
[here](https://docs.python.org/3/library/sys.html).
213215

216+
`sys.stdin`, `sys.stdout` and `sys.stderr` are [file objects](files.md),
217+
just like the file objects that `open()` gives us.
218+
214219
```python
215220
>>> import sys
216-
>>> # special files that the print and input functions use
217-
>>> # stdin is short for standard input
218-
>>> # stdout is short for standard output
219-
>>> # stderr is short for standard errors
220221
>>> print("Hello!", file=sys.stdout) # this is where prints go by default
221222
Hello!
222223
>>> print("Hello!", file=sys.stderr) # use this for error messages
@@ -235,8 +236,7 @@ sys.version_info(major=3, minor=4, micro=2, releaselevel='final', serial=0)
235236
>>> sys.exit() # exit out of Python
236237
```
237238

238-
If you use IDLE you'll notice that printing to `sys.stderr` makes
239-
the message show up in red instead of the normal blue.
239+
**TODO:** why stderr instead of stdout.
240240

241241
`sys.exit()` does the same thing as `sys.exit(0)`. The zero means that
242242
the program succeeded, and everything's fine. If our program has an
@@ -251,9 +251,6 @@ if something_went_wrong:
251251
sys.exit(1)
252252
```
253253

254-
`sys.exit` doesn't work for getting out of IDLE's `>>>` prompt. You can
255-
just close the window to get out of IDLE.
256-
257254
### Mathematics
258255

259256
There's no math.py anywhere, math is a built-in module like

0 commit comments

Comments
 (0)