|
| 1 | +# |
| 2 | +msgid "" |
| 3 | +msgstr "" |
| 4 | +"Project-Id-Version: Introduction to Programming with Python 0.1\n" |
| 5 | +"Report-Msgid-Bugs-To: \n" |
| 6 | +"POT-Creation-Date: 2013-10-25 09:37\n" |
| 7 | +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
| 8 | +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 9 | +"Language-Team: LANGUAGE <LL@li.org>\n" |
| 10 | +"MIME-Version: 1.0\n" |
| 11 | +"Content-Type: text/plain; charset=UTF-8\n" |
| 12 | +"Content-Transfer-Encoding: 8bit\n" |
| 13 | + |
| 14 | +#: ../../../source/conditional_loops.rst:2 |
| 15 | +msgid "Conditional Loops" |
| 16 | +msgstr "" |
| 17 | + |
| 18 | +#: ../../../source/conditional_loops.rst:4 |
| 19 | +msgid "Introduction" |
| 20 | +msgstr "" |
| 21 | + |
| 22 | +#: ../../../source/conditional_loops.rst:6 |
| 23 | +msgid "" |
| 24 | +"Conditional loops are way to repeat something while a certain condition is " |
| 25 | +"satisfied, or **True**. If the condition is always satisfied (never becomes " |
| 26 | +"**False**), the loop can become infinite. If the condition starts off false," |
| 27 | +" the code in the loop will never run! In Python conditional loops are " |
| 28 | +"defined with the ``while`` statement::" |
| 29 | +msgstr "" |
| 30 | + |
| 31 | +#: ../../../source/conditional_loops.rst:23 |
| 32 | +msgid "We call this part of the code the 'conditional': ``'.' not in word``" |
| 33 | +msgstr "" |
| 34 | + |
| 35 | +#: ../../../source/conditional_loops.rst:25 |
| 36 | +msgid "" |
| 37 | +"Whether the conditional return True or not determines whether the code " |
| 38 | +"inside the ``while`` loop runs." |
| 39 | +msgstr "" |
| 40 | + |
| 41 | +#: ../../../source/conditional_loops.rst:28 |
| 42 | +msgid "" |
| 43 | +"Read the code above, and see if you can summarise in your head what it what " |
| 44 | +"it do (what its final output will be)." |
| 45 | +msgstr "" |
| 46 | + |
| 47 | +#: ../../../source/conditional_loops.rst:31 |
| 48 | +msgid "" |
| 49 | +"Then copy it into a file, say :file:`sentence.py` and run it - see exactly " |
| 50 | +"what it does. Does that match up with what you thought?" |
| 51 | +msgstr "" |
| 52 | + |
| 53 | +#: ../../../source/conditional_loops.rst:36 |
| 54 | +msgid "" |
| 55 | +"If you are using Python 2, you will need to replace ``input`` with " |
| 56 | +"``raw_input`` to run the program correctly." |
| 57 | +msgstr "" |
| 58 | + |
| 59 | +#: ../../../source/conditional_loops.rst:40 |
| 60 | +msgid "Turtle prison" |
| 61 | +msgstr "" |
| 62 | + |
| 63 | +#: ../../../source/conditional_loops.rst:43 |
| 64 | +#: ../../../source/conditional_loops.rst:87 |
| 65 | +msgid "Exercise" |
| 66 | +msgstr "" |
| 67 | + |
| 68 | +#: ../../../source/conditional_loops.rst:45 |
| 69 | +msgid "" |
| 70 | +"The turtle has been up to its usual tricks again, robbing liqour stores and " |
| 71 | +"building up huge gambling debts. It's time for turtle to be put into a cell " |
| 72 | +"that it can't get out of." |
| 73 | +msgstr "" |
| 74 | + |
| 75 | +#: ../../../source/conditional_loops.rst:49 |
| 76 | +msgid "" |
| 77 | +"Let's make a new version of ``forward()``. One that will turn the turtle " |
| 78 | +"around if it tries to go further than 100 from the origin. We'll need a " |
| 79 | +"``while`` loop, and some new turtle functions:" |
| 80 | +msgstr "" |
| 81 | + |
| 82 | +#: ../../../source/conditional_loops.rst:53 |
| 83 | +msgid "``turtle.distance(0,0)`` - Distance of the turtle from the origin" |
| 84 | +msgstr "" |
| 85 | + |
| 86 | +#: ../../../source/conditional_loops.rst:54 |
| 87 | +msgid "``turtle.towards(0,0)`` - The angle to get back to origin" |
| 88 | +msgstr "" |
| 89 | + |
| 90 | +#: ../../../source/conditional_loops.rst:55 |
| 91 | +msgid "``turtle.setheading(angle)`` - Directly sets the turtle direction" |
| 92 | +msgstr "" |
| 93 | + |
| 94 | +#: ../../../source/conditional_loops.rst:57 |
| 95 | +msgid "" |
| 96 | +"You could try playing with a turtle in the interpreter and using these " |
| 97 | +"functions to check exactly what they do, if you like." |
| 98 | +msgstr "" |
| 99 | + |
| 100 | +#: ../../../source/conditional_loops.rst:60 |
| 101 | +msgid "" |
| 102 | +"Now you will need to implement the prison logic using these turtle " |
| 103 | +"functions, perhaps a ``while`` loop and a bit of conditional logic. It's a " |
| 104 | +"bit of a stretch but keep at it! Don't be afraid to talk it out with a coach" |
| 105 | +" or another student." |
| 106 | +msgstr "" |
| 107 | + |
| 108 | +#: ../../../source/conditional_loops.rst:66 |
| 109 | +#: ../../../source/conditional_loops.rst:104 |
| 110 | +msgid "Solution" |
| 111 | +msgstr "" |
| 112 | + |
| 113 | +#: ../../../source/conditional_loops.rst:80 |
| 114 | +msgid "Draw a spiral" |
| 115 | +msgstr "" |
| 116 | + |
| 117 | +#: ../../../source/conditional_loops.rst:82 |
| 118 | +msgid "" |
| 119 | +"Loops can be interrupted with the ``break`` statement. This is especially " |
| 120 | +"useful if you write an *infinite loop*, which is a loop where the " |
| 121 | +"conditional is always **True**." |
| 122 | +msgstr "" |
| 123 | + |
| 124 | +#: ../../../source/conditional_loops.rst:89 |
| 125 | +msgid "" |
| 126 | +"Write a ``while`` loop with a condition that is always **True** to draw a " |
| 127 | +"spiral. Interrupt the loop when the turtle reaches a certain distance from " |
| 128 | +"the center. Use the function ``turtle.distance(x, y)`` to get the turtle's " |
| 129 | +"distance to the point defined by the coordinates ``x`` and ``y``." |
| 130 | +msgstr "" |
| 131 | + |
| 132 | +#: ../../../source/conditional_loops.rst:94 |
| 133 | +msgid "" |
| 134 | +"To do this you will need the ``turtle.xcor()`` and ``turtle.ycor()`` " |
| 135 | +"functions, which return the position of the turtle in X and Y axes " |
| 136 | +"respectively." |
| 137 | +msgstr "" |
| 138 | + |
| 139 | +#: ../../../source/conditional_loops.rst:100 |
| 140 | +msgid "" |
| 141 | +"To draw a spiral, the turtle has to rotate by a constant value and move " |
| 142 | +"forward by an increasing value." |
| 143 | +msgstr "" |
| 144 | + |
| 145 | +#: ../../../source/conditional_loops.rst:120 |
| 146 | +msgid "Bonus" |
| 147 | +msgstr "" |
| 148 | + |
| 149 | +#: ../../../source/conditional_loops.rst:122 |
| 150 | +msgid "" |
| 151 | +"Can you make a conditional for this loop, so you don't need the infinite " |
| 152 | +"loop ``while True`` or the ``break``? Which version do you find easier to " |
| 153 | +"understand?" |
| 154 | +msgstr "" |
0 commit comments