Skip to content

Commit 00a2eee

Browse files
committed
Sphinx build
1 parent fa2838e commit 00a2eee

17 files changed

+363
-355
lines changed

en/_sources/conditional_loops.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Solution
2828
::
2929

3030
def move_to_window_border(distance):
31-
while xcor() + distance < window_width() / 2:
32-
forward(distance)
31+
while turtle.xcor() + distance < turtle.window_width() / 2:
32+
turtle.forward(distance)
3333

3434
Bonus
3535
-----
@@ -47,8 +47,8 @@ Exercise
4747

4848
Write a ``while`` loop with a condition that is always true to draw a spiral.
4949
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``.
50+
Use the function ``turtle.distance(x, y)`` to get the turtle's distance to the
51+
point defined by the coordinates ``x`` and ``y``.
5252

5353
.. note::
5454

@@ -63,9 +63,9 @@ Solution
6363
def draw_spiral(radius):
6464
speed = 1
6565
while True:
66-
forward(speed)
67-
left(10)
66+
turtle.forward(speed)
67+
turtle.left(10)
6868
speed += 0.1
69-
if distance(0, 0) > radius:
69+
if turtle.distance(0, 0) > radius:
7070
break
7171

en/_sources/conditionals.txt

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Conditional statements
44
Introduction
55
============
66

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*.
7+
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*.
88

99
To know if a condition is *True* of *False*, we need a new type of data:
1010
the booleans. They allow logical operations.
@@ -28,10 +28,10 @@ Here are some simple examples::
2828

2929
direction = -30
3030
if direction > 0 :
31-
forward(direction)
31+
turtle.forward(direction)
3232
else:
33-
left(180)
34-
forward (-direction)
33+
turtle.left(180)
34+
turtle.forward (-direction)
3535

3636

3737
Condition an action
@@ -47,22 +47,22 @@ We want the turtle to go forward for a specified distance (taken as a function p
4747
.. note::
4848
* We start from the center of the screen, which has coordinate (0;0)
4949
* We won't turn, until we reach the boundary our turtle wants to get away as quickly as possible
50-
* We can get the x coordinate of our turtle with the function *xcor*
51-
* We can get the width of the screen with the function *window_width*
50+
* We can get the x coordinate of our turtle with the function ``turtle.xcor()``
51+
* We can get the width of the screen with the function ``turtle.window_width()``
5252

5353
Solution
5454
--------
5555

5656
::
5757

5858
def stop_at_end_of_screen(distance):
59-
future_x_coord = xcor() + distance
60-
diff = window_width()/2-future_x_coord
59+
future_x_coord = turtle.xcor() + distance
60+
diff = turtle.window_width()/2 - future_x_coord
6161
if diff > 0 :
62-
forward(distance)
62+
turtle.forward(distance)
6363
else:
64-
forward(window_width()/2-xcor())
65-
left(180)
64+
turtle.forward(turtle.window_width()/2 - turtle.xcor())
65+
turtle.left(180)
6666

6767
Bonus exercise
6868
--------------
@@ -71,27 +71,24 @@ Now when the turtle reaches the end of the screen, it turns around and
7171
continue its movement in the other direction, the remaining of the distance
7272

7373
.. note::
74-
* heading() gives you the current angle the turtle's direction makes with the original east facing turtle. (a turtle going straight up has a heading of 90 degrees)
74+
* turtle.heading() gives you the current angle the turtle's direction makes with the original east facing turtle. (a turtle going straight up has a heading of 90 degrees)
7575

7676
Solution
7777
--------
7878

7979
::
8080

8181
def uturn_at_border(distance):
82-
if heading() == 0 :
83-
future_x_coord = xcor() + distance
82+
if turtle.heading() == 0 :
83+
future_x_coord = turtle.xcor() + distance
8484
else:
85-
future_x_coord = xcor() - distance
85+
future_x_coord = turtle.xcor() - distance
8686

87-
diff = window_width()/2-future_x_coord
87+
diff = turtle.window_width()/2 - future_x_coord
8888
if diff > 0 :
89-
forward(distance)
89+
turtle.forward(distance)
9090
else:
91-
forward(window_width()/2-xcor())
92-
left(180)
93-
forward (-diff)
91+
turtle.forward(turtle.window_width()/2 - turtle.xcor())
92+
turtle.left(180)
93+
turtle.forward(-diff)
9494

95-
96-
97-

en/_sources/functions.txt

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ There is still a lot of duplicated code --- the actual drawing of the rectangle
99
lacking abstractions. (Programmers call it a *code smell.*)
1010

1111
Functions are one way to express abstractions in Python. Let's take
12-
``reset()`` for example. It is actually an abstraction for a number of steps,
13-
namely:
12+
``turtle.reset()`` for example. It is actually an abstraction for a number of
13+
steps, namely:
1414

1515
* Erase the drawing board
1616
* Set the width and color back to default
@@ -19,15 +19,15 @@ namely:
1919
A function can be defined with the ``def`` keyword in Python::
2020

2121
def line_without_moving():
22-
forward(50)
23-
backward(50)
22+
turtle.forward(50)
23+
turtle.backward(50)
2424

2525
You can access names in functions as well::
2626

2727
size = 50
2828
def line_without_moving():
29-
forward(size)
30-
backward(size)
29+
turtle.forward(size)
30+
turtle.backward(size)
3131

3232
.. note:: Python uses *whitespaces to identify blocks of code* belonging together. While other languages use special characters (like curly brackets) in python a block is introduced with a colon at the end of the line and commands within a deeper identation level - ususally 4 spaces. The block ends with the first line with a lesser identation level.
3333

@@ -61,40 +61,40 @@ Solution
6161
::
6262

6363
def hexagon():
64-
forward(100)
65-
left(60)
66-
forward(100)
67-
left(60)
68-
forward(100)
69-
left(60)
70-
forward(100)
71-
left(60)
72-
forward(100)
73-
left(60)
74-
forward(100)
75-
left(60)
64+
turtle.forward(100)
65+
turtle.left(60)
66+
turtle.forward(100)
67+
turtle.left(60)
68+
turtle.forward(100)
69+
turtle.left(60)
70+
turtle.forward(100)
71+
turtle.left(60)
72+
turtle.forward(100)
73+
turtle.left(60)
74+
turtle.forward(100)
75+
turtle.left(60)
7676

7777
hexagon()
78-
forward(100)
79-
right(60)
78+
turtle.forward(100)
79+
turtle.right(60)
8080

8181
hexagon()
82-
forward(100)
83-
right(60)
82+
turtle.forward(100)
83+
turtle.right(60)
8484

8585
hexagon()
86-
forward(100)
87-
right(60)
86+
turtle.forward(100)
87+
turtle.right(60)
8888

8989
hexagon()
90-
forward(100)
91-
right(60)
90+
turtle.forward(100)
91+
turtle.right(60)
9292

9393
hexagon()
94-
forward(100)
95-
right(60)
94+
turtle.forward(100)
95+
turtle.right(60)
9696

9797
hexagon()
98-
forward(100)
99-
right(60)
98+
turtle.forward(100)
99+
turtle.right(60)
100100

en/_sources/functions_parameters.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ That is why we need to be able to give parameters, or also called *arguments* so
1010
Remember how we defined the function ``line_without_moving`` in the previous section::
1111

1212
def line_without_moving():
13-
forward(50)
14-
backward(50)
13+
turtle.forward(50)
14+
turtle.backward(50)
1515

1616
We can improve it by giving it a parameter::
1717

1818
def line_without_moving(length):
19-
forward(length)
20-
backward(length)
19+
turtle.forward(length)
20+
turtle.backward(length)
2121

2222
The parameter acts as a *name* only known inside the function's definition. We use the newly defined function by calling it with the value we want the parameter to have like this::
2323

@@ -29,10 +29,10 @@ We have been using functions with parameters since the beginning of the tutorial
2929

3030
And we can put as many arguments (or parameters) as we want, separating them with commas and giving them different names::
3131

32-
def tilted_line_without_moving(length,angle):
33-
left(angle)
34-
forward(length)
35-
backward(length)
32+
def tilted_line_without_moving(length, angle):
33+
turtle.left(angle)
34+
turtle.forward(length)
35+
turtle.backward(length)
3636

3737

3838
A parameterized function for a variable size hexagon
@@ -60,12 +60,12 @@ Solution
6060

6161
def hexagon(size):
6262
for i in range(6):
63-
forward(size)
64-
left(60)
63+
turtle.forward(size)
64+
turtle.left(60)
6565

66-
def honeycomb(size,count):
66+
def honeycomb(size, count):
6767
for i in range(count):
6868
hexagon(size)
69-
forward(size)
70-
right(60)
69+
turtle.forward(size)
70+
turtle.right(60)
7171

en/_sources/logical_operators.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ Logical operators
44
Introduction
55
============
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.
7+
Conditionals are a nice way to make decisions by asking if something equals
8+
true or not. But often one condition is not enough. For instance if we want to
9+
make a decision upon ``turtle.xcor()`` and ``turtle.ycor()`` we have to combine
10+
them. This can be done with logical operators.
1111

1212
This and that or something else
1313
===============================
1414

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
15+
Two easy to understand operators are ``and`` and ``or``. They do exactly whay
16+
the sound like: combine two statements in a way both have be true (``and``) or
1717
one of them has to be true (``or``)::
1818

1919
if 1 < 2 and 4 > 2:
@@ -31,7 +31,7 @@ want.
3131
Exercise
3232
--------
3333

34-
Create a function that accepts the argument ``angel`` and moves the turtle into
34+
Create a function that accepts the argument ``angle`` and moves the turtle into
3535
that direction until either the vertical or horizontal distance to the center
3636
exeeds 100.
3737

@@ -40,14 +40,16 @@ Solution
4040

4141
::
4242

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)
43+
def move_to_square_border(angle):
44+
turtle.left(angle)
45+
x = turtle.xcor()
46+
y = turtle.ycor()
47+
while x > -100 and x < 100 and y > -100 and y < 100:
48+
turtle.forward(10)
4749

4850
Bonus
4951
-----
5052

5153
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.
54+
angles. Use the ``turtle.home()`` function to make the turtle jump to the
55+
center after each line.

en/_sources/loops.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ Exercise
1818
--------
1919

2020
Draw a dashed line. You can move the turtle without tracing a line behind you
21-
with the ``up()`` function; put it back on the ground with ``down()``.
21+
with the ``turtle.up()`` function; put it back on the ground with
22+
``turtle.down()``.
2223

2324
.. image:: /images/dashed.png
2425

2526
Solution
27+
--------
2628

2729
::
2830

2931
for i in range(10):
30-
forward(15)
31-
up()
32-
forward(5)
33-
down()
32+
turtle.forward(15)
33+
turtle.up()
34+
turtle.forward(5)
35+
turtle.down()
3436

3537
Bonus
3638
-----
@@ -45,7 +47,7 @@ Honeycomb loops
4547
Exercise
4648
--------
4749

48-
Take your honeycomb program and make it easier with loops. How small can you
50+
Take your honeycomb program and make it easier with loops. How small can you
4951
get it?
5052

5153
Solution
@@ -55,10 +57,10 @@ Solution
5557

5658
def hexagon():
5759
for i in range(6):
58-
forward(100)
59-
left(60)
60+
turtle.forward(100)
61+
turtle.left(60)
6062

6163
for i in range(6):
62-
hexagon()
63-
forward(100)
64-
right(60)
64+
hexagon()
65+
turtle.forward(100)
66+
turtle.right(60)

0 commit comments

Comments
 (0)