Skip to content

Commit 6f6ccf0

Browse files
committed
Updated html files to stick to the source files
1 parent 454c5d4 commit 6f6ccf0

24 files changed

+10993
-266
lines changed

en/.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 5ce55d88e65e0217306dc230d617f309
3+
config: 56445c0dd197468cbf99ee917dc45c68
44
tags: fbb0d17656682115ca4d033fb2f83ba1

en/_sources/conditional_loops.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Conditional Loops
2+
*****************
3+
4+
Introduction
5+
============
6+
7+
8+
Exercise
9+
========
10+
11+

en/_sources/conditionals.txt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Conditional statements
2+
**********************
3+
Introduction
4+
============
5+
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+
8+
To know if a condition is *True* of *False*, we need a new type of data:
9+
the booleans. They allow logical operations.
10+
A logic statement or operation can be evaluated to be *true* or *false*.
11+
Our conditional statement can then be understood like this:
12+
13+
**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+
16+
17+
Examples
18+
========
19+
Here are some simple examples::
20+
21+
condition = True
22+
if condition:
23+
print "condition met"
24+
25+
if not condition:
26+
print "condition not met"
27+
28+
direction = -30
29+
if direction > 0 :
30+
forward(direction)
31+
else:
32+
left(180)
33+
forward (-direction)
34+
35+
36+
Condition an action
37+
===================
38+
39+
Exercise
40+
--------
41+
42+
Let's try to make our turtle to stop when it reaches the end
43+
of the window. Let's only take into account horizontal movements.
44+
We want the turtle to go forward for a specified distance (taken as a function parameter) until it reaches this distance, or stop and turn around if it reaches the border of the screen.
45+
46+
.. note::
47+
* 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 can get the x coordinate of our turtle with the function *xcor*
50+
* We can get the width of the screen with the function *window_width*
51+
52+
Solution
53+
--------
54+
55+
::
56+
57+
def stop_at_end_of_screen(distance):
58+
future_x_coord = xcor() + distance
59+
diff = window_width()/2-future_x_coord
60+
if diff > 0 :
61+
forward(distance)
62+
else:
63+
forward(window_width()/2-xcor())
64+
left(180)
65+
66+
Bonus exercise
67+
--------------
68+
69+
Now when the turtle reaches the end of the screen, it turns around and
70+
continue its movement in the other direction, the remaining of the distance
71+
72+
.. note::
73+
* 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+
75+
Solution
76+
--------
77+
78+
::
79+
80+
def uturn_at_border(distance):
81+
if heading() == 0 :
82+
future_x_coord = xcor() + distance
83+
else:
84+
future_x_coord = xcor() - distance
85+
86+
diff = window_width()/2-future_x_coord
87+
if diff > 0 :
88+
forward(distance)
89+
else:
90+
forward(window_width()/2-xcor())
91+
left(180)
92+
forward (-diff)
93+
94+
95+
96+

en/_sources/functions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ You can access names in functions as well::
2929
forward(size)
3030
backward(size)
3131

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.
33+
3234
A function for a square
3335
=======================
3436

en/_sources/functions_parameters.txt

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,72 @@
11
Functions with parameters
22
*************************
3+
Introduction
4+
============
5+
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.
8+
9+
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:
10+
11+
Remember how we defined the function ``line_without_moving`` in the previous section::
12+
13+
def line_without_moving():
14+
forward(50)
15+
backward(50)
16+
17+
We can improve it by giving it a parameter::
18+
19+
def line_without_moving(length):
20+
forward(length)
21+
backward(length)
22+
23+
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::
24+
25+
line_without_moving(50)
26+
line_without_moving(40)
27+
28+
We have been using functions with parameters since the beginning of the tutorial with the *forward*, *left*, etc...
29+
30+
31+
And we can put as many arguments (or parameters) as we want, separating them with commas and giving them different names::
32+
33+
def tilted_line_without_moving(length,angle):
34+
left(angle)
35+
forward(length)
36+
backward(length)
37+
38+
39+
A parameterised function for a variable size hexagon
40+
====================================================
41+
42+
Exercise
43+
--------
44+
Write a function that takes allows you to draw hexagons of any size you want, each time you call the function.
45+
46+
47+
48+
A function of several parameters
49+
================================
50+
51+
Exercise
52+
--------
53+
54+
Write a function that draws a honeycomb with a variable number of hexagons, of variable sizes
55+
56+
57+
Solution
58+
--------
59+
60+
::
61+
62+
def hexagon(size):
63+
for i in range(6):
64+
forward(size)
65+
left(60)
66+
67+
def honeycomb(size,count):
68+
for i in range(count):
69+
hexagon(size)
70+
forward(size)
71+
right(60)
372

4-
Todo

en/_sources/getting_started.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Getting started
2+
***************
3+
4+
Starting Python
5+
===============
6+
7+
After installing Python on your system successfully, you can start the interactive python prompt by typing "python" in the command and press <enter>. It will show you some context information about python similar to this::
8+
9+
Python 2.7.2 (default, Feb 1 2012, 00:28:57)
10+
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
11+
Type "help", "copyright", "credits" or "license" for more information.
12+
>>>
13+
14+
15+
.. note:: On windows the installer is not always setting up the "path" correctly. If that is the case on your system, you probably didn't see this message before but have to follow the steps described on the `python docs <http://docs.python.org/using/windows.html#excursus-setting-environment-variables>`_ and **restart your command line**.
16+
17+
Those three ">>>" in the last line indicate that you are now in the interactive shell of python. Type for example::
18+
19+
print("Hello world")
20+
21+
press <enter> and see what happens. You will now see the phrase "Hello world" appear and then python will bring you back to the interactive input, where you could enter another command now::
22+
23+
>>> print("Hello world")
24+
Hello world
25+
>>>
26+
27+
28+
Running python files
29+
====================
30+
31+
But you don't want to type everything into the Python shell everytime but have a file with commands for python to execute instead. In order to do that you can just pass a file name to the python command in your shell and it will execute that file. Let's try that. Just open the file "hello.py" in this directory in your favourite text editor and paste the print command from above. Now save that file, go back the command line and type::
32+
33+
python hello.py
34+
35+
When pressing <enter> now, the file is executed and you see the print as before. But this time, after python executed all commands from that file, it exited instead of going back to the interactive shell. In some opearting systems (and depending on your setup) you might also be able to just double click on the hello.py file to execute it
36+
37+
.. note:: Wordpad, TextEdit, Notepad and Word are **not** suited text editors. If you are unsure whether you already have a usable editor, you might want to download and install `Sublime Text2 <http://www.sublimetext.com/>`_. Sophisticated editors like this also take care of identation and help you run and debug your code.
38+
39+
And now we are all set and can get started with turtle.
40+
41+
42+
43+
44+

en/_sources/index.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ Table of contents:
77
.. toctree::
88
:maxdepth: 2
99

10-
interactive_work
10+
getting_started
1111
simple_drawing
1212
names
1313
functions
1414
loops
1515
functions_parameters
16-
16+
conditionals
17+
logical_operators
18+
conditional_loops

en/_sources/logical_operators.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Logical operators
2+
=========================
3+
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*)
6+
7+

en/_sources/names.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ After that statement, if you do ``print x``, it will actually output its value
2323

2424
forward(x)
2525

26+
27+
.. note:: You can not save numbers in variables, like we did here for "x", but you can actually save various kinds of things in them. A typical other thing you want to have store often is a "string" - a line of text. Strings are indicated with a starting and a leading \". You'll learn about this and other types, as those are called in python, and what you can do with them later on.
28+
2629
A variable called angle
2730
=======================
2831

0 commit comments

Comments
 (0)