Skip to content

Commit caa96e0

Browse files
committed
Sphinx build
1 parent 6f6ccf0 commit caa96e0

13 files changed

+449
-10111
lines changed

en/_sources/conditional_loops.txt

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,68 @@ Conditional Loops
44
Introduction
55
============
66

7+
Conditional loops are way to repeat something until a certain condition is met.
8+
If the condition is never met, the loop can become infinite. In Python
9+
conditional loops are defined with the ``while`` statement::
10+
11+
counter = 0
12+
while counter < 10:
13+
print "in the loop"
14+
counter += 1
15+
16+
Move until condition is met
17+
===========================
18+
19+
Exercise
20+
--------
21+
22+
Use the ``while`` loop to move the turtle forward until it reaches the end of
23+
the window.
24+
25+
Solution
26+
--------
27+
28+
::
29+
30+
def move_to_window_border(distance):
31+
while xcor() + distance < window_width() / 2:
32+
forward(distance)
33+
34+
Bonus
35+
-----
36+
37+
Can you make the turtle move exactly to the window border?
38+
39+
Draw a spiral
40+
=============
41+
42+
Loops can be interrupted with the ``break`` statement. This is often used in
43+
combination with infinite loops.
744

845
Exercise
9-
========
46+
--------
47+
48+
Write a ``while`` loop with a condition that is always true to draw a spiral.
49+
Interrupt the loop when the turtle reaches a certain distance from the center.
50+
Use the function ``distance(x, y)`` to get the turtle's distance to the point
51+
defined by the coordinates ``x`` and ``y``.
52+
53+
.. note::
54+
55+
To draw a spiral, the turtle has to rotate by a constant value and move
56+
forward by an increasing value in each repetition.
57+
58+
Solution
59+
--------
60+
61+
::
1062

63+
def draw_spiral(radius):
64+
speed = 1
65+
while True:
66+
forward(speed)
67+
left(10)
68+
speed += 0.1
69+
if distance(0, 0) > radius:
70+
break
1171

en/_sources/conditionals.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
Conditional statements
22
**********************
3+
34
Introduction
45
============
56

6-
So far we have accomplished predefined tasks, but in all honesty we were accomplishing no better achievements than the 18th century automata, or the music boxes following one set of instruction to the end. What makes programming so much more powerful is conditional statements. This is the ability to *test* a variable (or a name) against a value and act in one way if the condition is met by the variable or an other way if not. They are also commonly called by programmers *if statements*.
7+
So far we have accomplished predefined tasks, but in all honesty we were accomplishing no better achievements than the 18th century automate, or the music boxes following one set of instruction to the end. What makes programming so much more powerful is conditional statements. This is the ability to *test* a variable (or a name) against a value and act in one way if the condition is met by the variable or an other way if not. They are also commonly called by programmers *if statements*.
78

89
To know if a condition is *True* of *False*, we need a new type of data:
910
the booleans. They allow logical operations.
1011
A logic statement or operation can be evaluated to be *true* or *false*.
1112
Our conditional statement can then be understood like this:
1213

1314
**if** *(evaluation of a condition returns true)* **then** *do some operation* **else** *do an other operation*.
14-
And any operation that can be avaluated as *true* or *false* can but put to the test. All comparisons return *true* or *false*: *=,>,<*.
15+
And any operation that can be evaluated as *true* or *false* can but put to the test. All comparisons return *true* or *false*: *=,>,<*.
1516

1617

1718
Examples
@@ -45,7 +46,7 @@ We want the turtle to go forward for a specified distance (taken as a function p
4546

4647
.. note::
4748
* We start from the center of the screen, which has coordinate (0;0)
48-
* We won't turn, until we reach the boundery our turtle wants to get away as quickly as possible
49+
* We won't turn, until we reach the boundary our turtle wants to get away as quickly as possible
4950
* We can get the x coordinate of our turtle with the function *xcor*
5051
* We can get the width of the screen with the function *window_width*
5152

en/_sources/functions_parameters.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ Functions with parameters
33
Introduction
44
============
55

6-
Now we know how to *factorise* this code a little. But functions as we have defined them so far are not flexible. the variables are defined inside the function,
7-
and we need to rewrite a whole function to cahnge the value of an angle, or a distance in it.
6+
Now we know how to *factorize* this code a little. But functions as we have defined them so far are not flexible. The variables are defined inside the function, and we need to rewrite a whole function to change the value of an angle, or a distance in it.
87

98
That is why we need to be able to give parameters, or also called *arguments* so that *names* we use in the function can be used with different values each time we call the function:
109

@@ -36,7 +35,7 @@ And we can put as many arguments (or parameters) as we want, separating them wit
3635
backward(length)
3736

3837

39-
A parameterised function for a variable size hexagon
38+
A parameterized function for a variable size hexagon
4039
====================================================
4140

4241
Exercise

en/_sources/index.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ Table of contents:
1414
loops
1515
functions_parameters
1616
conditionals
17-
logical_operators
1817
conditional_loops
18+
logical_operators

en/_sources/logical_operators.txt

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,53 @@
11
Logical operators
2-
=========================
2+
*****************
33

4-
We can also do some more complex things with
5-
We can return the opposite of a logic operation, with **not** as a keyword in front of your expression, or combine several logic statements together with logical **and** and **or** links between them (they are usually called *operators*)
4+
Introduction
5+
============
66

7+
Conditionals are a nice way to make decisions by asking if something equals true
8+
or not. But often one condition is not enough. For instance if we want to make a
9+
decision upon ``xcor()`` and ``ycor()`` we have to combine them. This can be
10+
done with logical operators.
711

12+
This and that or something else
13+
===============================
14+
15+
Two easy to understand operators are ``and`` and ``or``. They do exactly whay the
16+
sound like: combine two statements in a way both have be true (``and``) or
17+
one of them has to be true (``or``)::
18+
19+
if 1 < 2 and 4 > 2:
20+
print "condition met"
21+
22+
if 1 < 2 and 4 < 10:
23+
print "condition not met"
24+
25+
if 4 < 10 or 1 < 2:
26+
print "condition met"
27+
28+
You are not restricted to one logical operator. You can combine as may as you
29+
want.
30+
31+
Exercise
32+
--------
33+
34+
Create a function that accepts the argument ``angel`` and moves the turtle into
35+
that direction until either the vertical or horizontal distance to the center
36+
exeeds 100.
37+
38+
Solution
39+
--------
40+
41+
::
42+
43+
def move_to_square_border(angel):
44+
left(angel)
45+
while xcor() > -100 and xcor() < 100 and ycor() > -100 and ycor() < 100:
46+
forward(10)
47+
48+
Bonus
49+
-----
50+
51+
Execute the ``move_to_square_border()`` function multiple times with different
52+
angels. Use the ``home()`` function to make the turtle jump to the center after
53+
each line.

0 commit comments

Comments
 (0)