Skip to content

Commit 4d8e757

Browse files
committed
fix program/input to program/code
1 parent f3a120e commit 4d8e757

226 files changed

Lines changed: 1722 additions & 1722 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/errorsAndDebug.ptx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ token</c>, neither of which is very informative.</p>
155155
condition.</p>
156156
<p>For example:</p>
157157
<program language="python">
158-
<input>
158+
<code>
159159
while x &gt; 0 and y &lt; 0:
160160
# do something to x
161161
# do something to y
162162

163163
print("x: ", x)
164164
print("y: ", y)
165165
print("condition: ", (x &gt; 0 and y &lt; 0))
166-
</input>
166+
</code>
167167
</program>
168168
<p>Now when you run the program, you will see three lines of output for each time
169169
through the loop. The last time through the loop, the condition should be
@@ -363,17 +363,17 @@ while x &gt; 0 and y &lt; 0:
363363
expression into a series of assignments to temporary variables.</p>
364364
<p>For example:</p>
365365
<program language="python">
366-
<input>
366+
<code>
367367
self.hands[i].addCard (self.hands[self.findNeighbor(i)].popCard())
368-
</input>
368+
</code>
369369
</program>
370370
<p>This can be rewritten as:</p>
371371
<program language="python">
372-
<input>
372+
<code>
373373
neighbor = self.findNeighbor (i)
374374
pickedCard = self.hands[neighbor].popCard()
375375
self.hands[i].addCard (pickedCard)
376-
</input>
376+
</code>
377377
</program>
378378
<p>The explicit version is easier to read because the variable names provide
379379
additional documentation, and it is easier to debug because you can check the
@@ -382,19 +382,19 @@ self.hands[i].addCard (pickedCard)
382382
evaluation may not be what you expect. For example, if you are translating the
383383
expression <c>x/2pi</c> into Python, you might write:</p>
384384
<program language="python">
385-
<input>
385+
<code>
386386
y = x / 2 * math.pi;
387-
</input>
387+
</code>
388388
</program>
389389
<p>That is not correct because multiplication and division have the same
390390
precedence and are evaluated from left to right. So this expression computes
391391
<c>(x/2)pi</c>.</p>
392392
<p>A good way to debug expressions is to add parentheses to make the order of
393393
evaluation explicit:</p>
394394
<program language="python">
395-
<input>
395+
<code>
396396
y = x / (2 * math.pi);
397-
</input>
397+
</code>
398398
</program>
399399
<p>Whenever you are not sure of the order of evaluation, use parentheses. Not
400400
only will the program be correct (in the sense of doing what you intended), it
@@ -407,16 +407,16 @@ y = x / (2 * math.pi);
407407
chance to print the <c>return</c> value before returning. Again, you can use a
408408
temporary variable. For example, instead of:</p>
409409
<program language="python">
410-
<input>
410+
<code>
411411
return self.hands[i].removeMatches()
412-
</input>
412+
</code>
413413
</program>
414414
<p>you could write:</p>
415415
<program language="python">
416-
<input>
416+
<code>
417417
count = self.hands[i].removeMatches()
418418
return count
419-
</input>
419+
</code>
420420
</program>
421421
<p>Now you have the opportunity to display or inspect the value of <c>count</c> before
422422
returning.</p>

pretext/Appendices/testmodule.ptx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
the <c>test</c> module. This test module is not included in the standard Python distribution. (There is
66
a standard test module but it is different from this.) What follows is the source code for this <c>test</c> module.</p>
77
<program language="python">
8-
<input>
8+
<code>
99
def testEqual(actual,expected,places=5):
1010
'''
1111
Does the actual value equal the expected value?
@@ -21,7 +21,7 @@ def testEqual(actual,expected,places=5):
2121
return True
2222
print('\tTest Failed: expected {} but got {}'.format(expected,actual))
2323
return False
24-
</input>
24+
</code>
2525
</program>
2626
<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>
2727
</section>

pretext/ClassesBasics/AddingOtherMethodstoourClass.ptx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<p>Let's add two simple methods to allow a point to give us information about its state. The <c>getX</c> method, when invoked, will return the value of the x coordinate. The implementation of this method is straight forward since we already know how
1616
to write functions that return values. One thing to notice is that even though the <c>getX</c> method does not need any other parameter information to do its work, there is still one formal parameter, <c>self</c>. As we stated earlier, all methods defined in a class that operate on objects of that class will have <c>self</c> as their first parameter. Again, this serves as reference to the object itself which in turn gives access to the state data inside the object.</p>
1717
<program xml:id="chp13_classes4" interactive="activecode" language="python">
18-
<input>
18+
<code>
1919
class Point:
2020
""" Point class for representing and manipulating x,y coordinates. """
2121

@@ -34,14 +34,14 @@ class Point:
3434
p = Point(7, 6)
3535
print(p.getX())
3636
print(p.getY())
37-
</input>
37+
</code>
3838
</program>
3939
<p>Note that the <c>getX</c> method simply returns the value of <c>self.x</c> from the object itself. In other words, the implementation of the method is to go to the state of the object itself and get the value of <c>x</c>. Likewise, the <c>getY</c> method looks the same.</p>
4040
<p>Let's add another method, <c>distanceFromOrigin</c>, to see better how methods
4141
work. This method will again not need any additional information to do its work.
4242
It will perform a more complex task.</p>
4343
<program xml:id="chp13_classes5" interactive="activecode" language="python">
44-
<input>
44+
<code>
4545
class Point:
4646
""" Point class for representing and manipulating x,y coordinates. """
4747

@@ -62,7 +62,7 @@ class Point:
6262

6363
p = Point(7, 6)
6464
print(p.distanceFromOrigin())
65-
</input>
65+
</code>
6666
</program>
6767
<p>Notice that the caller of <c>distanceFromOrigin</c> does not explicitly
6868
supply an argument to match the <c>self</c> parameter. This is true of all method calls. The definition will always

pretext/ClassesBasics/ConvertinganObjecttoaString.ptx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<p>When we're working with classes and objects, it is often necessary to print an object (that is to print the state of an object).
55
Consider the example below.</p>
66
<program xml:id="chp13_classesstr1" interactive="activecode" language="python">
7-
<input>
7+
<code>
88
class Point:
99
""" Point class for representing and manipulating x,y coordinates. """
1010

@@ -25,7 +25,7 @@ class Point:
2525

2626
p = Point(7, 6)
2727
print(p)
28-
</input>
28+
</code>
2929
</program>
3030
<p>The <c>print</c> function shown above produces a string representation of the Point <c>p</c>. The default functionality provided by
3131
Python tells you that <c>p</c> is an object of type <c>Point</c>. However, it does not tell you anything about the specific
@@ -36,7 +36,7 @@ print(p)
3636
have decided that the string representation will include the values of x and y as well as some identifying text. It
3737
is required that the <c>__str__</c> method create and <em>return</em> a string.</p>
3838
<program xml:id="chp13_classesstr2" interactive="activecode" language="python">
39-
<input>
39+
<code>
4040
class Point:
4141
""" Point class for representing and manipulating x,y coordinates. """
4242

@@ -59,7 +59,7 @@ class Point:
5959

6060
p = Point(7, 6)
6161
print(p)
62-
</input>
62+
</code>
6363
</program>
6464
<p>When we run the program above you can see that the <c>print</c> function now shows the string that we chose.</p>
6565
<p>Now, you ask, don't we already have an <c>str</c> type converter that can

pretext/ClassesBasics/Exercises.ptx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
computes the distance between that point and self.</p>
99
</statement>
1010
<program interactive="activecode" language="python" xml:id="classes_q1_editor">
11-
<input>
11+
<code>
1212

13-
</input>
13+
</code>
1414
</program>
1515
<solution>
1616
<program xml:id="ch_cl_ex_1_answer" language="python">
17-
<input>
17+
<code>
1818
import math
1919

2020
class Point:
@@ -42,7 +42,7 @@ class Point:
4242
p = Point(3, 3)
4343
q = Point(6, 7)
4444
print(p.distanceFromPoint(q))
45-
</input>
45+
</code>
4646
</program>
4747
</solution>
4848
</exercise>
@@ -53,9 +53,9 @@ print(p.distanceFromPoint(q))
5353
<c>Point(3, 5).reflect_x()</c> is (3, -5)</p>
5454
</statement>
5555
<program xml:id="ch_cl_02_editor" interactive="activecode" language="python">
56-
<input>
56+
<code>
5757

58-
</input>
58+
</code>
5959
</program>
6060
</exercise>
6161
<exercise label="classes_q3">
@@ -67,13 +67,13 @@ print(p.distanceFromPoint(q))
6767
<p>What cases will cause your method to fail? Return None when it happens.</p>
6868
</statement>
6969
<program interactive="activecode" language="python" xml:id="classes_q3_editor">
70-
<input>
70+
<code>
7171

72-
</input>
72+
</code>
7373
</program>
7474
<solution>
7575
<program xml:id="ch_cl_ex_3_answer" language="python">
76-
<input>
76+
<code>
7777
class Point:
7878
""" Point class for representing and manipulating x,y coordinates. """
7979

@@ -100,7 +100,7 @@ class Point:
100100

101101
p = Point(4, 10)
102102
print(p.slope_from_origin())
103-
</input>
103+
</code>
104104
</program>
105105
</solution>
106106
</exercise>
@@ -117,9 +117,9 @@ print(p.slope_from_origin())
117117
When will your method fail?</p>
118118
</statement>
119119
<program xml:id="ch_cl_04_editor" interactive="activecode" language="python">
120-
<input>
120+
<code>
121121

122-
</input>
122+
</code>
123123
</program>
124124
</exercise>
125125
<exercise label="classes_q5">
@@ -129,13 +129,13 @@ print(p.slope_from_origin())
129129
state of the point)</p>
130130
</statement>
131131
<program interactive="activecode" language="python" xml:id="classes_q5_editor">
132-
<input>
132+
<code>
133133

134-
</input>
134+
</code>
135135
</program>
136136
<solution>
137137
<program xml:id="ch_cl_05_answer" language="python">
138-
<input>
138+
<code>
139139
class Point:
140140
""" Point class for representing and manipulating x,y coordinates. """
141141

@@ -165,7 +165,7 @@ p = Point(7, 6)
165165
print(p)
166166
p.move(5, 10)
167167
print(p)
168-
</input>
168+
</code>
169169
</program>
170170
</solution>
171171
</exercise>
@@ -174,9 +174,9 @@ print(p)
174174
<p>Given three points that fall on the circumference of a circle, find the center and radius of the circle.</p>
175175
</statement>
176176
<program xml:id="classes_q6_editor" interactive="activecode" language="python">
177-
<input>
177+
<code>
178178

179-
</input>
179+
</code>
180180
</program>
181181
</exercise>
182182
</exercises>

pretext/ClassesBasics/ImprovingourConstructor.ptx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
<p>We can make our class constructor more general by putting extra parameters into
77
the <c>__init__</c> method, as shown in this codelens example.</p>
88
<program xml:id="chp13_improveconstructor" interactive="codelens" language="python">
9-
<input>
9+
<code>
1010
class Point:
1111
""" Point class for representing and manipulating x,y coordinates. """
12-
12+
1313
def __init__(self, initX, initY):
1414
""" Create a new point at the given coordinates. """
1515
self.x = initX
1616
self.y = initY
17-
17+
1818
p = Point(7, 6)
19-
</input>
19+
</code>
2020
</program>
2121
<p>Now when we create new points, we supply the x and y coordinates as parameters. When the point is created, the values of <c>initX</c> and <c>initY</c> are assigned to the state of the object.</p>
2222
<image source="ClassesBasics/Figures/objectpic5.png" width="50%" alt="Simple object has state and methods"/>

pretext/ClassesBasics/InstancesasReturnValues.ptx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
it <c>halfway</c> that takes another <c>Point</c> as a parameter and returns the <c>Point</c> that is halfway between the point and
1010
the target.</p>
1111
<program xml:id="chp13_classesmid1" interactive="activecode" language="python">
12-
<input>
12+
<code>
1313
class Point:
1414

1515
def __init__(self, initX, initY):
@@ -41,7 +41,7 @@ mid = p.halfway(q)
4141
print(mid)
4242
print(mid.getX())
4343
print(mid.getY())
44-
</input>
44+
</code>
4545
</program>
4646
<p>The resulting Point, <c>mid</c>, has an x value of 4 and a y value of 8. We can also use any other methods since <c>mid</c> is a
4747
<c>Point</c> object.</p>
@@ -51,10 +51,10 @@ print(mid.getY())
5151
<note>
5252
<p>This workspace is provided for your convenience. You can use this activecode window to try out anything you like.</p>
5353
<program xml:id="scratch_cl_01" interactive="activecode" language="python">
54-
<input>
54+
<code>
5555

5656

57-
</input>
57+
</code>
5858
</program>
5959
</note>
6060
</section>

pretext/ClassesBasics/ObjectsasArgumentsandParameters.ptx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<p>Here is a simple function called <c>distance</c> involving our new <c>Point</c> objects. The job of this function is to figure out the
99
distance between two points.</p>
1010
<program xml:id="chp13_classes6" interactive="activecode" language="python">
11-
<input>
11+
<code>
1212
import math
1313

1414
class Point:
@@ -38,7 +38,7 @@ def distance(point1, point2):
3838
p = Point(4, 3)
3939
q = Point(0, 0)
4040
print(distance(p, q))
41-
</input>
41+
</code>
4242
</program>
4343
<p><c>distance</c> takes two points and returns the distance between them. Note that <c>distance</c> is <term>not</term> a method of the Point class. You can see this by looking at the indentation pattern. It is not inside the class definition. The other way we
4444
can know that <c>distance</c> is not a method of Point is that <c>self</c> is not included as a formal parameter. In addition, we do not invoke <c>distance</c> using the dot notation.</p>

0 commit comments

Comments
 (0)