You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: if.md
+20-15Lines changed: 20 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -2,45 +2,50 @@
2
2
3
3
### Using if statements
4
4
5
-
Back in chapter 2, we learned what the boolean values True and False are.
5
+
Now we know what True and False are.
6
6
7
7
```py
8
8
>>>1==1
9
9
True
10
10
>>>1==2
11
11
False
12
12
>>>
13
-
```
14
-
15
-
We also learned how to assign them to variables.
16
-
17
-
```py
18
13
>>> its_raining =True
19
14
>>> its_raining
20
15
True
21
16
>>>
22
17
```
23
18
24
-
But what if we want to execute different code depending on something? That's when `if` comes in.
19
+
But what if we want to execute different code depending on something?
20
+
That's when `if` comes in.
25
21
26
22
```py
27
23
>>> its_raining =True
28
24
>>>if its_raining:
29
-
print("It's raining!")
30
-
31
-
25
+
...print("It's raining!")
26
+
...
32
27
It's raining!
33
28
>>> its_raining =False
34
29
>>>if its_raining:
35
-
print("It's raining!") # nothing happens
30
+
...print("It's raining!") # nothing happens
31
+
...
32
+
>>>
33
+
```
36
34
35
+
The prompt changed from `>>>` to `...`. It meant that Python was
36
+
expecting me to keep typing. When I was done, I just pressed Enter
37
+
twice. My code was execute and the prompt was restored to `>>>`.
37
38
38
-
>>>
39
-
```
39
+
At this point it's easier to put your code into a file and use it
40
+
there. If you use IDLE, go to File at top left and select New File, or
41
+
just press Ctrl+N.
42
+
43
+

40
44
41
-
After typing the line with print we need to press Enter twice to actually run the code we wrote. IDLE also indents everything we want to run if it's raining.
45
+
If you are not using IDLE, open whatever editor you have installed, or
46
+
install
42
47
43
-
At this point it's easier to put your code into a file and use it there. The file's content would be like this:
0 commit comments