Skip to content

Commit 02ab912

Browse files
committed
reconvert
1 parent 6d81e79 commit 02ab912

115 files changed

Lines changed: 1104 additions & 391 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pretext/Appendices/foo

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<section xml:id="appendices_test-module-source-code">
2+
<title><c>test</c> module source code</title>
3+
<p>Starting in the Functions chapter, we have written unit tests using the <c>testEqual</c> function from
4+
the <c>test</c> module. This test module is not included in the standard Python distribution. (There is
5+
a standard test module but it is different from this.) What follows is the source code for this <c>test</c> module.</p>
6+
<program language="python"><input>
7+
def testEqual(actual,expected,places=5):
8+
'''
9+
Does the actual value equal the expected value?
10+
For floats, places indicates how many places, right of the decimal, must be correct
11+
'''
12+
if isinstance(expected,float):
13+
if abs(actual-expected) &lt; 10**(-places):
14+
print('\tPass')
15+
return True
16+
else:
17+
if actual == expected:
18+
print('\tPass')
19+
return True
20+
print('\tTest Failed: expected {} but got {}'.format(expected,actual))
21+
return False
22+
</input></program>
23+
<p>To use this module when programming on your own computer, save the above code with the name <term>test.py</term> in the same folder as the python program you want to test.</p>
24+
</section>
25+

pretext/ClassesBasics/Exercises.ptx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<exercises xml:id="classes-basics_exercises">
33
<title>Exercises</title>
4-
<exercise xml:id="classes_q1">
4+
<exercise label="classes_q1">
55
<statement>
66
<p>Add a <c>distanceFromPoint</c> method that works similar to <c>distanceFromOrigin</c> except that it
77
takes a <c>Point</c> as a parameter and
@@ -46,7 +46,7 @@ print(p.distanceFromPoint(q))
4646
</program>
4747
</solution>
4848
</exercise>
49-
<exercise xml:id="ch_cl_02">
49+
<exercise label="ch_cl_02">
5050
<statement>
5151
<p>Add a method <c>reflect_x</c> to Point which returns a new Point, one which is the
5252
reflection of the point about the x-axis. For example,
@@ -58,7 +58,7 @@ print(p.distanceFromPoint(q))
5858
</input>
5959
</program>
6060
</exercise>
61-
<exercise xml:id="classes_q3">
61+
<exercise label="classes_q3">
6262
<statement>
6363
<p>Add a method <c>slope_from_origin</c> which returns the slope of the line joining the origin
6464
to the point. For example,</p>
@@ -104,7 +104,7 @@ print(p.slope_from_origin())
104104
</program>
105105
</solution>
106106
</exercise>
107-
<exercise xml:id="ch_cl_04">
107+
<exercise label="ch_cl_04">
108108
<statement>
109109
<p>The equation of a straight line is <q>y = ax + b</q>, (or perhaps <q>y = mx + c</q>).
110110
The coefficients a and b completely describe the line. Write a method in the
@@ -122,7 +122,7 @@ print(p.slope_from_origin())
122122
</input>
123123
</program>
124124
</exercise>
125-
<exercise xml:id="classes_q5">
125+
<exercise label="classes_q5">
126126
<statement>
127127
<p>Add a method called <c>move</c> that will take two parameters, call them <c>dx</c> and <c>dy</c>. The method will
128128
cause the point to move in the x and y direction the number of units given. (Hint: you will change the values of the
@@ -169,7 +169,7 @@ print(p)
169169
</program>
170170
</solution>
171171
</exercise>
172-
<exercise xml:id="classes_q6">
172+
<exercise label="classes_q6">
173173
<statement>
174174
<p>Given three points that fall on the circumference of a circle, find the center and radius of the circle.</p>
175175
</statement>

pretext/ClassesBasics/UserDefinedClasses.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ alex = Turtle()
125125
<p>
126126
<term>Check Your Understanding</term>
127127
</p>
128-
<exercise xml:id="chp17_objects">
128+
<exercise label="chp17_objects">
129129
<statement>
130130
<p>What is the the output of the following print code?</p>
131131
<program language="python">

pretext/ClassesDiggingDeeper/Exercises.ptx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<exercises xml:id="classes-digging-deeper_exercises">
33
<title>Exercises</title>
4-
<exercise xml:id="classes_deeper_q1">
4+
<exercise label="classes_deeper_q1">
55
<statement>
66
<p>We can represent a rectangle by knowing three things: the location of its lower left corner, its width, and its height.
77
Create a class definition for a Rectangle class using this idea. To create a Rectangle object at location (4,5) with width 6
@@ -50,7 +50,7 @@ print(r)
5050
</program>
5151
</solution>
5252
</exercise>
53-
<exercise xml:id="ch_cl2_q2">
53+
<exercise label="ch_cl2_q2">
5454
<statement>
5555
<p>Add the following accessor methods to the Rectangle class: <c>getWidth</c>, <c>getHeight</c>, <c>__str__</c>.</p>
5656
</statement>
@@ -60,7 +60,7 @@ print(r)
6060
</input>
6161
</program>
6262
</exercise>
63-
<exercise xml:id="ch_cl2_q3">
63+
<exercise label="ch_cl2_q3">
6464
<statement>
6565
<p>Add a method <c>area</c> to the Rectangle class that returns the area of any instance:</p>
6666
<pre>r = Rectangle(Point(0, 0), 10, 5)
@@ -107,7 +107,7 @@ class Rectangle:
107107
</program>
108108
</solution>
109109
</exercise>
110-
<exercise xml:id="ch_cl2_q4">
110+
<exercise label="ch_cl2_q4">
111111
<statement>
112112
<p>Write a <c>perimeter</c> method in the Rectangle class so that we can find
113113
the perimeter of any rectangle instance:</p>
@@ -120,7 +120,7 @@ test(r.perimeter(), 30)</pre>
120120
</input>
121121
</program>
122122
</exercise>
123-
<exercise xml:id="ch_cl2_q5">
123+
<exercise label="ch_cl2_q5">
124124
<statement>
125125
<p>Write a <c>transpose</c> method in the Rectangle class that swaps the width
126126
and the height of any rectangle instance:</p>
@@ -174,7 +174,7 @@ class Rectangle:
174174
</program>
175175
</solution>
176176
</exercise>
177-
<exercise xml:id="ch_cl2_q6">
177+
<exercise label="ch_cl2_q6">
178178
<statement>
179179
<p>Write a new method in the Rectangle class to test if a Point falls within
180180
the rectangle. For this exercise, assume that a rectangle at (0,0) with
@@ -196,7 +196,7 @@ test(r.contains(Point(-3, -3)), False)</pre>
196196
</input>
197197
</program>
198198
</exercise>
199-
<exercise xml:id="ch_cl2_q7">
199+
<exercise label="ch_cl2_q7">
200200
<statement>
201201
<p>Write a new method called <c>diagonal</c> that will return the length of the diagonal that runs
202202
from the lower left corner to the opposite corner.</p>
@@ -244,7 +244,7 @@ class Rectangle:
244244
</program>
245245
</solution>
246246
</exercise>
247-
<exercise xml:id="ch_cl2_q8">
247+
<exercise label="ch_cl2_q8">
248248
<statement>
249249
<p>In games, we often put a rectangular <q>bounding box</q> around our sprites in
250250
the game. We can then do <em>collision detection</em> between, say, bombs and

pretext/Debugging/HowtoAvoidDebugging.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ print(final_time)
6666
</input>
6767
</program>
6868
<p>Hmm, when you run this example you see that something unexpected has happened. You would not realize this was an error unless you first knew what the program was supposed to do.</p>
69-
<exercise xml:id="db_q_ex3_1">
69+
<exercise label="db_q_ex3_1">
7070
<statement>
7171
<p>Which of the following best describes what is wrong with the previous example?</p>
7272
</statement>

pretext/Debugging/KnowyourerrorMessages.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ print(final_time_int)
3434
Python interpreter. The interpreter in activecode is limited in many ways, but it is intended for beginners,
3535
including the wording chosen to describe errors.</p>
3636
</note>
37-
<exercise xml:id="db_qex32">
37+
<exercise label="db_qex32">
3838
<statement>
3939
<p>Which of the following explains why <c>wait_time_int = int(wait_time_int)</c> is an error?</p>
4040
</statement>

pretext/Dictionaries/Aliasingandcopying.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ acopy['right'] = 'left' # does not change opposites
2828
<p>
2929
<term>Check your understanding</term>
3030
</p>
31-
<exercise xml:id="test_question11_4_1">
31+
<exercise label="test_question11_4_1">
3232
<statement>
3333
<p>What is printed by the following statements?</p>
3434
<program language="python">

pretext/Dictionaries/Dictionarymethods.ptx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ print(inventory.get("cherries", 0))
162162
<p>
163163
<term>Check your understanding</term>
164164
</p>
165-
<exercise xml:id="test_question11_3_1">
165+
<exercise label="test_question11_3_1">
166166
<statement>
167167
<p>What is printed by the following statements?</p>
168168
<program language="python">
@@ -209,7 +209,7 @@ print(keylist[3])
209209
</choice>
210210
</choices>
211211
</exercise>
212-
<exercise xml:id="test_question11_3_2">
212+
<exercise label="test_question11_3_2">
213213
<statement>
214214
<p>What is printed by the following statements?</p>
215215
<program language="python">
@@ -255,7 +255,7 @@ print(answer)
255255
</choice>
256256
</choices>
257257
</exercise>
258-
<exercise xml:id="test_question11_3_3">
258+
<exercise label="test_question11_3_3">
259259
<statement>
260260
<p>What is printed by the following statements?</p>
261261
<program language="python">
@@ -284,7 +284,7 @@ print("dog" in mydict)
284284
</choice>
285285
</choices>
286286
</exercise>
287-
<exercise xml:id="test_question11_3_4">
287+
<exercise label="test_question11_3_4">
288288
<statement>
289289
<p>What is printed by the following statements?</p>
290290
<program language="python">
@@ -313,7 +313,7 @@ print(23 in mydict)
313313
</choice>
314314
</choices>
315315
</exercise>
316-
<exercise xml:id="test_question11_3_5">
316+
<exercise label="test_question11_3_5">
317317
<statement>
318318
<p>What is printed by the following statements?</p>
319319
<program language="python">

pretext/Dictionaries/Dictionaryoperations.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<p>
1818
<term>Check your understanding</term>
1919
</p>
20-
<exercise xml:id="test_question11_2_1">
20+
<exercise label="test_question11_2_1">
2121
<statement>
2222
<p>What is printed by the following statements?</p>
2323
<program language="python">

pretext/Dictionaries/Exercises.ptx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<exercises xml:id="dictionaries_exercises">
33
<title>Exercises</title>
4-
<exercise xml:id="ex_11_01">
4+
<exercise label="ex_11_01">
55
<statement>
66
<p>Write a program that allows the user to enter a string. It then prints a
77
table of the letters of the alphabet in alphabetical order which occur in
@@ -134,7 +134,7 @@ add_fruit(new_inventory, 'strawberries', 25)
134134
# test that new_inventory['strawberries'] is now 35)
135135
</input>
136136
</program>
137-
<exercise xml:id="ex_11_02">
137+
<exercise label="ex_11_02">
138138
<statement>
139139
<p>Write a program called <c>alice_words.py</c> that creates a text file named
140140
<c>alice_words.txt</c> containing an alphabetical listing of all the words, and the
@@ -302,7 +302,7 @@ print("The word 'alice' appears " + str(count['alice']) + " times in the book.")
302302
</input></program>
303303
</solution>
304304
</exercise>
305-
<exercise xml:id="ex_11_03">
305+
<exercise label="ex_11_03">
306306
<statement>
307307
<p>What is the longest word in Alice in Wonderland? How many characters does it have?</p>
308308
</statement>
@@ -312,7 +312,7 @@ print("The word 'alice' appears " + str(count['alice']) + " times in the book.")
312312
</input>
313313
</program>
314314
</exercise>
315-
<exercise xml:id="ex_11_04">
315+
<exercise label="ex_11_04">
316316
<statement>
317317
<p>Here's a table of English to Pirate translations</p>
318318
<table>

0 commit comments

Comments
 (0)