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
@@ -71,27 +71,24 @@ Now when the turtle reaches the end of the screen, it turns around and
71
71
continue its movement in the other direction, the remaining of the distance
72
72
73
73
.. 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)
Copy file name to clipboardExpand all lines: docs/en/functions.rst
+30-30Lines changed: 30 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,8 @@ There is still a lot of duplicated code --- the actual drawing of the rectangle
9
9
lacking abstractions. (Programmers call it a *code smell.*)
10
10
11
11
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:
14
14
15
15
* Erase the drawing board
16
16
* Set the width and color back to default
@@ -19,15 +19,15 @@ namely:
19
19
A function can be defined with the ``def`` keyword in Python::
20
20
21
21
def line_without_moving():
22
-
forward(50)
23
-
backward(50)
22
+
turtle.forward(50)
23
+
turtle.backward(50)
24
24
25
25
You can access names in functions as well::
26
26
27
27
size = 50
28
28
def line_without_moving():
29
-
forward(size)
30
-
backward(size)
29
+
turtle.forward(size)
30
+
turtle.backward(size)
31
31
32
32
.. 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.
Copy file name to clipboardExpand all lines: docs/en/functions_parameters.rst
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,14 +10,14 @@ That is why we need to be able to give parameters, or also called *arguments* so
10
10
Remember how we defined the function ``line_without_moving`` in the previous section::
11
11
12
12
def line_without_moving():
13
-
forward(50)
14
-
backward(50)
13
+
turtle.forward(50)
14
+
turtle.backward(50)
15
15
16
16
We can improve it by giving it a parameter::
17
17
18
18
def line_without_moving(length):
19
-
forward(length)
20
-
backward(length)
19
+
turtle.forward(length)
20
+
turtle.backward(length)
21
21
22
22
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::
23
23
@@ -29,10 +29,10 @@ We have been using functions with parameters since the beginning of the tutorial
29
29
30
30
And we can put as many arguments (or parameters) as we want, separating them with commas and giving them different names::
31
31
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)
36
36
37
37
38
38
A parameterized function for a variable size hexagon
0 commit comments