Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pretext/AdditionalTopics/Dictionaryoperations.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>The <c>del</c> statement removes a key-value pair from a dictionary. For example,
the following dictionary contains the names of various fruits and the number of
each fruit in stock. If someone buys all of the pears, we can remove the entry from the dictionary.</p>
<program xml:id="ch15_sec3_c1" interactive="codelens" language="python">
<program xml:id="ch15_sec3_c1" interactive="activecode" language="python">
<input>
inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}

Expand All @@ -16,7 +16,7 @@
be modified by referencing an association on the left hand side of the assignment statement. In the previous
example, instead of deleting the entry for <c>pears</c>, we could have set the inventory to <c>0</c>.
</p>
<program xml:id="ch15_sec3_c2" interactive="codelens" language="python">
<program xml:id="ch15_sec3_c2" interactive="activecode" language="python">
<input>
inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}

Expand All @@ -25,7 +25,7 @@
</program>
<p>Similarily,
a new shipment of 200 bananas arriving could be handled like this.</p>
<program xml:id="ch15_sec3_c3" interactive="codelens" language="python">
<program xml:id="ch15_sec3_c3" interactive="activecode" language="python">
<input>
inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
inventory['bananas'] = inventory['bananas'] + 200
Expand Down
14 changes: 7 additions & 7 deletions pretext/AdditionalTopics/intro-Dictionaries.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
<p>One way to create a dictionary is to start with the empty dictionary and add
<term>key-value pairs</term>. The empty dictionary is denoted <c>{}</c>
</p>
<program xml:id="ch15_sec2_c1" interactive="codelens" language="python">
<program xml:id="ch15_sec2_c1" interactive="activecode" language="python">
<input>
eng2sp = {}
eng2sp['one'] = 'uno'
eng2sp['two'] = 'dos'
eng2sp['three'] = 'tres'
eng2sp = {}
eng2sp['one'] = 'uno'
eng2sp['two'] = 'dos'
eng2sp['three'] = 'tres'
</input>
</program>
<p>The first assignment creates an empty dictionary named <c>eng2sp</c>. The other
Expand All @@ -35,7 +35,7 @@
For our purposes we can think of this ordering as unpredictable.</p>
<p>Another way to create a dictionary is to provide a list of key-value pairs
using the same syntax as the previous output.</p>
<program xml:id="ch15_sec2_p1" interactive="codelens" language="python">
<program xml:id="ch15_sec2_p1" interactive="activecode" language="python">
<input>
eng2sp = {'three': 'tres', 'one': 'uno', 'two': 'dos'}
print(eng2sp)
Expand All @@ -46,7 +46,7 @@
accessed with keys, not with indices, so there is no need to care about
ordering.</p>
<p>Here is how we use a key to look up the corresponding value.</p>
<program xml:id="ch15_sec2_p2" interactive="codelens" language="python">
<program xml:id="ch15_sec2_p2" interactive="activecode" language="python">
<input>
eng2sp = {'three': 'tres', 'one': 'uno', 'two': 'dos'}

Expand Down
2 changes: 1 addition & 1 deletion pretext/ClassesBasics/ImprovingourConstructor.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
provide some additional capability for the user to pass information to the constructor. Since constructors are simply specially named functions, we can use parameters (as we've seen before) to provide the specific information.</p>
<p>We can make our class constructor more general by putting extra parameters into
the <c>__init__</c> method, as shown in this codelens example.</p>
<program xml:id="ch13_sec5_c1" interactive="codelens" language="python">
<program xml:id="ch13_sec5_c1" interactive="activecode" language="python">
<input>
class Point:
""" Point class for representing and manipulating x,y coordinates. """
Expand Down
2 changes: 1 addition & 1 deletion pretext/ClassesBasics/UserDefinedClasses.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ print("Nothing seems to have happened with the points")
having an x and y coordinate with value 0. However, because we have not asked the point to do anything, we don't see any other result.</p>
<image source="ClassesBasics/Figures/objectpic4.png" width="50%" alt="Simple object has state and methods"/>
<p>You can see this for yourself, via codelens:</p>
<program xml:id="ch13_sec4_c1" interactive="codelens" language="python">
<program xml:id="ch13_sec4_c1" interactive="activecode" language="python">
<input>
class Point:
""" Point class for representing and manipulating x,y coordinates. """
Expand Down
2 changes: 1 addition & 1 deletion pretext/ComplexLogic/Aliasing.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ print(a is b)
is <term>aliased</term>. Changes made with one alias affect the other. In the codelens example below, you can see that <c>a</c> and <c>b</c> refer
to the same list after executing the assignment statement <c>b = a</c>.
</p>
<program xml:id="chp09_is3" interactive="codelens" language="python">
<program xml:id="chp09_is3" interactive="activecode" language="python">
<input>
a = [81, 82, 83]
b = [81, 82, 83]
Expand Down
2 changes: 1 addition & 1 deletion pretext/ComplexLogic/ObjectsandReferences.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ print(a == b)
<c>a</c> and <c>b</c> have the same value but do not refer to the same object.</p>
<p>There is one other important thing to notice about this reference diagram. The variable <c>a</c> is a reference to a <term>collection of references</term>. Those references actually refer to the integer values in the list. In other words, a list is a collection of references to objects. Interestingly, even though <c>a</c> and <c>b</c> are two different lists (two different collections of references), the integer object <c>81</c> is shared by both. Like strings, integers are also immutable so Python optimizes and lets everyone share the same object for some commonly used small integers.</p>
<p>Here is the example in codelens. Pay particular attention to the <title_reference>id</title_reference> values.</p>
<program xml:id="ch10_sec7_c1" interactive="codelens" language="python">
<program xml:id="ch10_sec7_c1" interactive="activecode" language="python">
<input>
a = [81, 82, 83]
b = [81, 82, 83]
Expand Down
2 changes: 1 addition & 1 deletion pretext/ComplexLogic/PureFunctions.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ print(things)
</input>
</program>
<p>Once again, codelens helps us to see the actual references and objects as they are passed and returned.</p>
<program xml:id="ch10_sec9_p2" interactive="codelens" language="python">
<program xml:id="ch10_sec9_p2" interactive="activecode" language="python">
<input>
def doubleStuff(a_list):
""" Return a new list in which contains doubles of the elements in a_list. """
Expand Down
2 changes: 1 addition & 1 deletion pretext/ComplexLogic/RepetitionandReferences.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ print(newlist)
<image source="Lists/Figures/refrep2.png" width="50%" alt="Same reference"/>
<p>Here is the same example in codelens. Step through the code paying particular attention to the result of executing the assignment statement <c>origlist[1] = 99</c>.
</p>
<program xml:id="reprefstep" interactive="codelens" language="python">
<program xml:id="reprefstep" interactive="activecode" language="python">
<input>
origlist = [45, 76, 34, 55]

Expand Down
2 changes: 1 addition & 1 deletion pretext/ComplexLogic/TheAccumulatorPatternwithStrings.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if eachChar != 'a' and eachChar != 'e' and eachChar != 'i' and
<p>Take a close look also at the initialization of <c>sWithoutVowels</c>. We start with an empty string and then begin adding
new characters to the end.</p>
<p>Step through the function using codelens to see the accumulator variable grow.</p>
<program xml:id="ch10_sec6_c1" interactive="codelens" language="python">
<program xml:id="ch10_sec6_c1" interactive="activecode" language="python">
<input>
def removeVowels(s):
vowels = "aeiouAEIOU"
Expand Down
2 changes: 1 addition & 1 deletion pretext/ComplexLogic/UsingListsasParameters.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ print(things)
If a function modifies the elements of a list parameter, the caller sees the change since the change
is occurring to the original.</p>
<p>This can be easily seen in codelens. Note that after the call to <c>doubleStuff</c>, the formal parameter <c>aList</c> refers to the same object as the actual parameter <c>things</c>. There is only one copy of the list object itself.</p>
<program xml:id="ch10_sec8_c1" interactive="codelens" language="python">
<program xml:id="ch10_sec8_c1" interactive="activecode" language="python">
<input>
def doubleStuff(aList):
""" Overwrite each element in aList with double its value. """
Expand Down
6 changes: 3 additions & 3 deletions pretext/Dictionaries/Dictionaryoperations.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p>The <c>del</c> statement removes a key-value pair from a dictionary. For example,
the following dictionary contains the names of various fruits and the number of
each fruit in stock. If someone buys all of the pears, we can remove the entry from the dictionary.</p>
<program xml:id="ch12_dict4" interactive="codelens" language="python">
<program xml:id="ch12_dict4" interactive="activecode" language="python">
<input>
inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}

Expand All @@ -16,7 +16,7 @@
be modified by referencing an association on the left hand side of the assignment statement. In the previous
example, instead of deleting the entry for <c>pears</c>, we could have set the inventory to <c>0</c>.
</p>
<program xml:id="ch12_dict4a" interactive="codelens" language="python">
<program xml:id="ch12_dict4a" interactive="activecode" language="python">
<input>
inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}

Expand All @@ -25,7 +25,7 @@
</program>
<p>Similarily,
a new shipment of 200 bananas arriving could be handled like this.</p>
<program xml:id="ch12_dict5" interactive="codelens" language="python">
<program xml:id="ch12_dict5" interactive="activecode" language="python">
<input>
inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217}
inventory['bananas'] = inventory['bananas'] + 200
Expand Down
6 changes: 3 additions & 3 deletions pretext/Dictionaries/intro-Dictionaries.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p>One way to create a dictionary is to start with the empty dictionary and add
<term>key-value pairs</term>. The empty dictionary is denoted <c>{}</c>
</p>
<program xml:id="chp12_dict1" interactive="codelens" language="python">
<program xml:id="chp12_dict1" interactive="activecode" language="python">
<input>
eng2sp = {}
eng2sp['one'] = 'uno'
Expand All @@ -35,7 +35,7 @@
For our purposes we can think of this ordering as unpredictable.</p>
<p>Another way to create a dictionary is to provide a list of key-value pairs
using the same syntax as the previous output.</p>
<program xml:id="chp12_dict2" interactive="codelens" language="python">
<program xml:id="chp12_dict2" interactive="activecode" language="python">
<input>
eng2sp = {'three': 'tres', 'one': 'uno', 'two': 'dos'}
print(eng2sp)
Expand All @@ -46,7 +46,7 @@
accessed with keys, not with indices, so there is no need to care about
ordering.</p>
<p>Here is how we use a key to look up the corresponding value.</p>
<program xml:id="chp12_dict3" interactive="codelens" language="python">
<program xml:id="chp12_dict3" interactive="activecode" language="python">
<input>
eng2sp = {'three': 'tres', 'one': 'uno', 'two': 'dos'}

Expand Down
2 changes: 1 addition & 1 deletion pretext/Functions/BooleanFunctions.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ else:
</program>
<p>Here is the same program in codelens. When we evaluate the <c>if</c> statement in the main part of the program, the evaluation of
the boolean expression causes a call to the <c>isDivisible</c> function. This is very easy to see in codelens.</p>
<program xml:id="ch8_sec10_c1" interactive="codelens" language="python">
<program xml:id="ch8_sec10_c1" interactive="activecode" language="python">
<input>
def isDivisible(x, y):
return x % y == 0
Expand Down
2 changes: 1 addition & 1 deletion pretext/Functions/Functionscancallotherfunctions.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
first function called <c>square</c> simply computes the square of a given number.
The second function called <c>sum_of_squares</c> makes use of square to compute
the sum of three numbers that have been squared.</p>
<program xml:id="ch8_sec5_p1" interactive="codelens" language="python">
<program xml:id="ch8_sec5_p1" interactive="activecode" language="python">
<input>
def square(x):
y = x * x
Expand Down
4 changes: 2 additions & 2 deletions pretext/Functions/Functionsthatreturnvalues.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ print("The result of", toSquare, "squared is", result)
we will see later where it makes sense to have a return statement even when other statements
follow, and the further statements are <em>not</em> executed.</p>
</note>
<program xml:id="ch8_sec2_c1" interactive="codelens" language="python">
<program xml:id="ch8_sec2_c1" interactive="activecode" language="python">
<input>
def square(x):
y = x * x
Expand Down Expand Up @@ -130,7 +130,7 @@ print("The result of", toSquare, "squared is", squareResult)
programmers. As you step through this example, pay very close attention to the return
value in the local variables listing. Then look at what is printed when the
function returns.</p>
<program xml:id="ch8_sec2_c2" interactive="codelens" language="python">
<program xml:id="ch8_sec2_c2" interactive="activecode" language="python">
<input>
def square(x):
y = x * x
Expand Down
2 changes: 1 addition & 1 deletion pretext/Functions/TheAccumulatorPattern.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ print("The result of", toSquare, "squared is", squareResult)
the for statement? Not sure? Try it and find out.</p>
</note>
<p>Here is the same program in codelens. Step through the function and watch the <q>running total</q> accumulate the result.</p>
<program xml:id="ch8_sec4_c1" interactive="codelens" language="python">
<program xml:id="ch8_sec4_c1" interactive="activecode" language="python">
<input>
def square(x):
runningtotal = 0
Expand Down
6 changes: 3 additions & 3 deletions pretext/Functions/Variablesandparametersarelocal.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
variable on the left hand side of the assignment operator. It is called local because this variable only
exists inside the function and you cannot use it outside. For example,
consider again the <c>square</c> function:</p>
<program xml:id="ch8_sec3_c1" interactive="codelens" language="python">
<program xml:id="ch8_sec3_c1" interactive="activecode" language="python">
<input>
def square(x):
y = x * x
Expand Down Expand Up @@ -62,7 +62,7 @@ print(result)
<p>There is another variation on this theme of local versus global variables. Assignment statements in the local function cannot
change variables defined outside the function, without further (discouraged) special syntax. Consider the following
codelens example:</p>
<program xml:id="ch8_sec3_c2" interactive="codelens" language="python">
<program xml:id="ch8_sec3_c2" interactive="activecode" language="python">
<input>
def powerof(x, p):
power = p # Another dumb mistake
Expand Down Expand Up @@ -96,7 +96,7 @@ print(result)
formal parameter will cause a change to the value of the variable that was
used as the actual parameter, especially when the two share the same name.
But this example demonstrates that that is clearly not how Python operates.</p>
<program xml:id="ch8_sec3_c3" interactive="codelens" language="python">
<program xml:id="ch8_sec3_c3" interactive="activecode" language="python">
<input>
def square(x):
y = x * x
Expand Down
8 changes: 0 additions & 8 deletions pretext/GeneralIntro/Glossary.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<section xml:id="general-intro_glossary">
<title>Glossary</title>
<glossary sorted="False">
<gi>
<title>activecode</title>
<p>A unique interpreter environment that allows Python to be executed from within a web browser.</p>
</gi>
<gi>
<title>algorithm</title>
<p>A general step by step process for solving a problem.</p>
Expand All @@ -20,10 +16,6 @@
modern languages first compile source code into byte code and then
interpret the byte code with a program called a <em>virtual machine</em>.</p>
</gi>
<gi>
<title>codelens</title>
<p>An interactive environment that allows the user to control the step by step execution of a Python program</p>
</gi>
<gi>
<title>comment</title>
<p>Information in a program that is meant for other programmers (or anyone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ print(2 + 3)
In codelens you can see and control the step by step progress.
Note that the red arrow always points to the next line of code that is going to be executed.
The light green arrow points to the line that was just executed.</p>
<program xml:id="ch1_sec4_c1" interactive="codelens" language="python">
<program xml:id="ch1_sec4_c1" interactive="activecode" language="python">
<input>
print("My first program adds two numbers, 2 and 3:")
print(2 + 3)
Expand Down
2 changes: 1 addition & 1 deletion pretext/Iteration/2DimensionalIterationImageProcessing.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ for i in range(5):
</program>
<p>Another way to see this in more detail is to examine the behavior with codelens. Step through the iterations to see the
flow of control as it occurs with the nested iteration. Again, for every value of <c>i</c>, all of the values of <c>j</c> will occur. You can see that the inner iteration completes before going on to the next pass of the outer iteration.</p>
<program xml:id="nested2" interactive="codelens" language="python">
<program xml:id="nested2" interactive="activecode" language="python">
<input>
for i in range(5):
for j in range(3):
Expand Down
2 changes: 1 addition & 1 deletion pretext/Iteration/FlowofExecutionofthewhileLoop.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p>A codelens demonstration is a good way to help you visualize exactly how the flow of control
works with the while loop. Try stepping forward and backward through the program by pressing
the buttons. You can see the value of <c>count</c> change as the loop iterates through the values from 10 to 0.</p>
<program xml:id="ch7_sec3_c1" interactive="codelens" language="python">
<program xml:id="ch7_sec3_c1" interactive="activecode" language="python">
<input>
count = 10
while count > 0:
Expand Down
2 changes: 1 addition & 1 deletion pretext/Iteration/NewtonsMethod.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ prin(betterapprox)
enough to the previous one, we can write a function for computing the square root that uses the number of iterations necessary and no more.</p>
<p>This implementation, shown in codelens,
uses a <c>while</c> condition to execute until the approximation is no longer changing. Each time through the loop we compute a <q>better</q> approximation using the formula described earlier. As long as the <q>better</q> is different, we try again. Step through the program and watch the approximations get closer and closer.</p>
<program xml:id="chp07_newtonswhile" interactive="codelens" language="python">
<program xml:id="chp07_newtonswhile" interactive="activecode" language="python">
<input>
n = 10
approx = 0.5 * n
Expand Down
4 changes: 2 additions & 2 deletions pretext/Iteration/TherangeFunction.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ print(list(range(1, 5)))
</program>
<p>Codelens will help us to further understand the way range works. In this case, the variable <c>i</c> will take on values
produced by the <c>range</c> function.</p>
<program xml:id="ch7_sec9_c1" interactive="codelens" language="python">
<program xml:id="ch7_sec9_c1" interactive="activecode" language="python">
<input>
for i in range(10):
print(i)
Expand All @@ -86,7 +86,7 @@ print(list(range(10, 0, -1)))
</input>
</program>
<p>Try it in codelens. Do you see why the first two statements produce the same result?</p>
<program xml:id="ch7_sec9_c2" interactive="codelens" language="python">
<program xml:id="ch7_sec9_c2" interactive="activecode" language="python">
<input>
for i in range(0, 20, 2):
print(i)
Expand Down
2 changes: 1 addition & 1 deletion pretext/Iteration/ThewhileStatement.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

<!--<p>The same program in codelens will allow you to observe the flow of execution.</p>

<program xml:id="ch7_sec2_p3" interactive="codelens" language="python">
<program xml:id="ch7_sec2_p3" interactive="activecode" language="python">
<input>
""" Return the sum of 1+2+3 ... n """
aBound = int(input("Please give a number n: "))
Expand Down
2 changes: 1 addition & 1 deletion pretext/Iteration/TraversalandthewhileLoop.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ while position &lt; len(fruit):
executed. The last character accessed is the one with the index
<c>len(fruit)-1</c>, which is the last character in the string.</p>
<p>Here is the same example in codelens so that you can trace the values of the variables.</p>
<program xml:id="ch7_sec5_c1" interactive="codelens" language="python">
<program xml:id="ch7_sec5_c1" interactive="activecode" language="python">
<input>
fruit = "apple"

Expand Down
Loading