Skip to content

Commit 43c11d1

Browse files
committed
Merge branch 'master' of github.com:RunestoneInteractive/thinkcspy
2 parents 2c590f2 + 3f4798e commit 43c11d1

95 files changed

Lines changed: 1471 additions & 1068 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.

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ node_modules
1414
# don't track error logs
1515
.error_schema.log
1616
cli.log
17+
logs
1718

1819
# don't track OS related files (windows/macos/linux)
1920
.DS_Store
@@ -88,4 +89,9 @@ GitHub.sublime-settings
8889
.dropbox
8990
.dropbox.attr
9091
.dropbox.cache
91-
92+
__pycache__
93+
published
94+
pretext/GenFigs
95+
sphinx_settings.json
96+
rs-substitutes.xml
97+
**/GenFigs

README.rst

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ works.
1717

1818
.. image:: https://travis-ci.org/RunestoneInteractive/thinkcspy.svg?branch=master
1919
:target: https://travis-ci.org/RunestoneInteractive/thinkcspy
20-
20+
2121
Getting Started
2222
===============
2323

24-
We have tried to make it as easy as possible for you to build and use this book.
24+
We have tried to make it as easy as possible for you to build and use this book.
2525

2626
You can see and read this book online at `runestone.academy <http://runestone.academy/ns/books/published/thinkcspy/index.html?mode=browsing>`_
2727

@@ -33,7 +33,7 @@ Building with PreTeXt
3333
1. Create a virtual environment
3434
2. pip install pretextbook
3535
3. To build run: pretext build web
36-
4. pretext view html
36+
4. pretext view web
3737

3838
Note: The pretext sources are in the pretext folder, we will keep the _sources folder until we are 100% sure that the book has been converted correctly and as thoroughly as possible.
3939

@@ -50,16 +50,13 @@ Building a PDF
5050

5151
1. clone this repo
5252
2. install pretext with ``pip install pretext``
53-
3. run ``pretext build --generate ALL pdf`` This will generate the needed assets and then try to build the pdf. You generally only need to include the ``--generate ALL`` the first time you build the pdf. After that you can just run ``pretext build pdf``
54-
55-
Note -- As of June 2023, the pdf build is not working. It builds the first few pages and then there is a latex error. We would love some help fixing this. For that it may be helpful to use the latex target and then manually run latex on the resulting latex source in the output/latex folder.
56-
53+
3. run ``pretext build pdf`` This will generate the needed assets and then try to build the pdf. The pdf will be in the output/pdf folder.
5754

5855

5956
Building with runestone
6057
-----------------------
6158

62-
As mentioned above this method is deprecated, but will still work.
59+
As mentioned above this method is deprecated, but will still work.
6360
Any updates to this book should be made in PreTeXt NOT RST.
6461

6562
You can build it and host it yourself in just a few simple steps:

_sources/Lists/Exercises.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Exercises
201201
.. activecode:: lst_q5_answer
202202

203203
def max(lst):
204-
max = 0
204+
max = lst[0]
205205
for e in lst:
206206
if e > max:
207207
max = e

_sources/Strings/Exercises.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,12 @@ Exercises
156156
if achar == 'e':
157157
numberOfe = numberOfe + 1
158158

159-
percent_with_e = (numberOfe / totalChars) * 100
160-
print("Your text contains", totalChars, "alphabetic characters of which", numberOfe, "(", percent_with_e, "%)", "are 'e'.")
161-
159+
if totalChars != 0:
160+
percent_with_e = (numberOfe / totalChars) * 100
161+
print("Your text contains", totalChars, "alphabetic characters of which", numberOfe, "(", percent_with_e, "%)", "are 'e'.")
162+
else:
163+
print("There were no characters in the input string p")
164+
return (numberOfe)
162165

163166
p = '''
164167
"If the automobile had followed the same development cycle as the computer, a

pretext/ClassesBasics/UserDefinedClasses.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ print("Nothing seems to have happened with the points")
6666
</input>
6767
</program>
6868
<p>During the initialization of the objects, we created two
69-
attributes called <title_reference>x</title_reference> and <title_reference>y</title_reference> for each, and gave them both the value 0.</p>
69+
attributes called x and y for each, and gave them both the value 0.</p>
7070
<note>
7171
<p>The asignments are not to <c>x</c> and <c>y</c>, but to <c>self.x</c> and <c>self.y</c>.
7272
The attributes <c>x</c> and <c>y</c> are <em>always</em> attached to a particular instance.

pretext/ClassesBasics/toctree.ptx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:lang="en-US">
3-
4<title>Classes and Objects - the Basics</title>
4-
4<xi:include href="./Objectorientedprogramming.ptx"/>
5-
4<xi:include href="./Achangeofperspective.ptx"/>
6-
4<xi:include href="./ObjectsRevisited.ptx"/>
7-
4<xi:include href="./UserDefinedClasses.ptx"/>
8-
4<xi:include href="./ImprovingourConstructor.ptx"/>
9-
4<xi:include href="./AddingOtherMethodstoourClass.ptx"/>
10-
4<xi:include href="./ObjectsasArgumentsandParameters.ptx"/>
11-
4<xi:include href="./ConvertinganObjecttoaString.ptx"/>
12-
4<xi:include href="./InstancesasReturnValues.ptx"/>
13-
4<xi:include href="./Glossary.ptx"/>
14-
4<xi:include href="./Exercises.ptx"/>
3+
<title>Classes and Objects - the Basics</title>
4+
<xi:include href="./Objectorientedprogramming.ptx"/>
5+
<xi:include href="./Achangeofperspective.ptx"/>
6+
<xi:include href="./ObjectsRevisited.ptx"/>
7+
<xi:include href="./UserDefinedClasses.ptx"/>
8+
<xi:include href="./ImprovingourConstructor.ptx"/>
9+
<xi:include href="./AddingOtherMethodstoourClass.ptx"/>
10+
<xi:include href="./ObjectsasArgumentsandParameters.ptx"/>
11+
<xi:include href="./ConvertinganObjecttoaString.ptx"/>
12+
<xi:include href="./InstancesasReturnValues.ptx"/>
13+
<xi:include href="./Glossary.ptx"/>
14+
<xi:include href="./Exercises.ptx"/>
1515
</chapter>

pretext/ClassesDiggingDeeper/Fractions.ptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
on the top is called the numerator and the number on the bottom is called the denominator. Sometimes people use a slash
1010
for the line and sometimes they use a straight line. The fact is that it really does not matter so long as you know which
1111
is the numerator and which is the denominator.</p>
12-
<p>To design our class, we simply need to use the analysis above to realize that the <title_reference>state</title_reference> of a fraction object can be
12+
<p>To design our class, we simply need to use the analysis above to realize that the state of a fraction object can be
1313
completely described by representing two integers. We can begin by implementing the <c>Fraction</c> class and the <c>__init__</c>
1414
method which will allow the user to provide a numerator and a denominator for the fraction being created.</p>
1515
<program xml:id="fractions_init" interactive="activecode" language="python">
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:lang="en-US">
3-
4<title>Classes and Objects - Digging a Little Deeper</title>
4-
4<xi:include href="./Fractions.ptx"/>
5-
4<xi:include href="./ObjectsareMutable.ptx"/>
6-
4<xi:include href="./Sameness.ptx"/>
7-
4<xi:include href="./ArithmeticMethods.ptx"/>
8-
4<xi:include href="./Glossary.ptx"/>
9-
4<xi:include href="./Exercises.ptx"/>
3+
<title>Classes and Objects - Digging a Little Deeper</title>
4+
<xi:include href="./Fractions.ptx"/>
5+
<xi:include href="./ObjectsareMutable.ptx"/>
6+
<xi:include href="./Sameness.ptx"/>
7+
<xi:include href="./ArithmeticMethods.ptx"/>
8+
<xi:include href="./Glossary.ptx"/>
9+
<xi:include href="./Exercises.ptx"/>
1010
</chapter>

pretext/Debugging/KnowyourerrorMessages.ptx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0"?>
22
<section xml:id="debugging_know-your-error-messages">
33
<title>Know Your Error Messages</title>
4-
<introduction>
4+
<subsection>
5+
<title>Introduction</title>
56
<p>Many problems in your program will lead to an error message. For example as I was writing and testing this chapter of the book I wrote the following version of the example program in the previous section.</p>
67
<program language="python">
78
<input>
@@ -228,7 +229,7 @@ print(final_time_int)
228229
</li>
229230
</ul>
230231
</p>
231-
</introduction>
232+
</subsection>
232233
<subsection xml:id="debugging_parseerror">
233234
<title>ParseError</title>
234235
<p>Parse errors happen when you make an error in the syntax of your program. Syntax errors are like making grammatical errors in writing. If you don't use periods and commas in your writing then you are making it hard for other readers to figure out what you are trying to say. Similarly Python has certain grammatical rules that must be followed or else Python can't figure out what you are trying to say.</p>
@@ -247,7 +248,7 @@ wait_time_int = int(wait_time_str)
247248
final_time_int = current_time_int + wait_time_int
248249
print(final_time_int)
249250
Since the error message points us to line 4 this might be a bit confusing. If you look at line four carefully you will see that there is no problem with the syntax. So, in this case the next step should be to back up and look at the previous line. In this case if you look at line 2 carefully you will see that there is a missing right parenthesis at the end of the line. Remember that parenthses must be balanced. Since Python allows statements to continue over multiple lines inside parentheses Python will continue to scan subsequent lines looking for the balancing right parenthesis. However in this case it finds the name current_time_int and it will want to interpret that as another parameter to the input function. But, there is not a comma to separate the previous string from the variable so as far as Python is concerned the error here is a missing comma. From your perspective its a missing parenthesis.
250-
251+
251252
<program language="python">
252253
<input>
253254
current_time_str = input("What is the current time (in hours 0-23)?")
@@ -278,7 +279,7 @@ wait_time_int = int(wait_time_str)
278279
final_time_int = current_time_int + wait_time_int
279280
print(final_time_int)
280281
The error message points you to line 1 and in this case that is exactly where the error occurs. In this case your biggest clue is to notice the difference in highlighting on the line. Notice that the words <q>current time</q> are a different color than those around them. Why is this? Because <q>current time</q> is in double quotes inside another pair of double quotes Python thinks that you are finishing off one string, then you have some other names and finally another string. But you haven't separated these names or strings by commas, and you haven't added them together with the concatenation operator (+). So, there are several corrections you could make. First you could make the argument to input be as follows: "What is the 'current time' (in hours 0-23)" Notice that here we have correctly used single quotes inside double quotes. Another option is to simply remove the extra double quotes. Why were you quoting <q>current time</q> anyway? "What is the current time (in hours 0-23)"
281-
282+
282283
<program language="python">
283284
<input>
284285
current_time_str = input("What is the "current time" (in hours 0-23)?")
@@ -296,7 +297,7 @@ print(final_time_int)
296297
</solution>
297298
</exercise>
298299
<p>
299-
<term>Finding Clues</term> If you follow the same advice as for the last problem, comment out line one, you will immediately get a different error message. Here's where you need to be very careful and not panic. The error message you get now is: <c>NameError: name 'current_time_str' is not defined on line 4</c>. You might be very tempted to think that this is somehow related to the earlier problem and immediately conclude that there is something wrong with the variable name <c>current_time_str</c> but if you reflect for a minute you will see that by commenting out line one you have caused a new and unrelated error. That is you have commented out the creation of the name <c>current_time_str</c>. So of course when you want to convert it to an <c>int</c> you will get the NameError. Yes, this can be confusing, but it will become much easier with experience. It's also important to keep calm, and evaluate each new clue carefully so you don't waste time chasing problems that are not really there.</p>
300+
<term>Finding Clues</term> If you follow the same advice as for the last problem, comment out line one, you will immediately get a different error message. Here's where you need to be very careful and not panic. The error message you get now is: <c>NameError: name 'current_time_str' is not defined on line </c>. You might be very tempted to think that this is somehow related to the earlier problem and immediately conclude that there is something wrong with the variable name <c>current_time_str</c> but if you reflect for a minute you will see that by commenting out line one you have caused a new and unrelated error. That is you have commented out the creation of the name <c>current_time_str</c>. So of course when you want to convert it to an <c>int</c> you will get the NameError. Yes, this can be confusing, but it will become much easier with experience. It's also important to keep calm, and evaluate each new clue carefully so you don't waste time chasing problems that are not really there.</p>
300301
<p>Uncomment line 1 and you are back to the ParseError. Another track is to eliminate a possible source of error. Rather than commenting out the entire line you might just try to assign <c>current_time_str</c> to a constant value. For example you might make line one look like this: <c>current_time_str = "10" #input("What is the "current time" (in hours 0-23)?")</c>. Now you have assigned <c>current_time_str</c> to the string 10, and commented out the input statement. And now the program works! So you conclude that the problem must have something to do with the input function.</p>
301302
</subsection>
302303
<subsection xml:id="debugging_typeerror">
@@ -449,6 +450,7 @@ print(final_time_int)
449450
</input>
450451
</program>
451452
<p>Run the program but instead of typing in anything to the dialog box just click OK. You should see the following error message: <c>ValueError: invalid literal for int() with base 10: '' on line: 4</c> This error is not because you have made a mistake in your program. Although sometimes we do want to check the user input to make sure its valid, but we don't have all the tools we need for that yet. The error happens because the user did not give us something we can convert to an integer, instead we gave it an empty string. Try running the program again. Now this time enter <q>ten</q> instead of the number 10. You will get a similar error message.</p>
453+
<p>Run the program but instead of typing in anything to the dialog box just click OK. You should see the following error message: <c>ValueError: invalid literal for int() with base 10: '' on line: </c> This error is not because you have made a mistake in your program. Although sometimes we do want to check the user input to make sure its valid, but we don't have all the tools we need for that yet. The error happens because the user did not give us something we can convert to an integer, instead we gave it an empty string. Try running the program again. Now this time enter <q>ten</q> instead of the number 10. You will get a similar error message.</p>
452454
<p>ValueErrors are not always caused by user input error, but in this program that is the case. We'll look again at ValueErrors again when we get to more complicated programs. For now it is worth repeating that you need to keep track of the restrictions needed for your variables, and understand what your function is expecting. You can do this by writing comments in your code, or by naming your variables in a way that reminds you of their proper form.</p>
453455
</subsection>
454456
</section>

pretext/Debugging/toctree.ptx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:lang="en-US">
3-
4<title>Debugging Interlude 1</title>
4-
4<xi:include href="./intro-HowtobeaSuccessfulProgrammer.ptx"/>
5-
4<xi:include href="./HowtoAvoidDebugging.ptx"/>
6-
4<xi:include href="./BeginningtipsforDebugging.ptx"/>
7-
4<xi:include href="./KnowyourerrorMessages.ptx"/>
8-
4<xi:include href="./Summary.ptx"/>
9-
4<xi:include href="./Exercises.ptx"/>
3+
<title>Debugging Interlude 1</title>
4+
<xi:include href="./intro-HowtobeaSuccessfulProgrammer.ptx"/>
5+
<xi:include href="./HowtoAvoidDebugging.ptx"/>
6+
<xi:include href="./BeginningtipsforDebugging.ptx"/>
7+
<xi:include href="./KnowyourerrorMessages.ptx"/>
8+
<xi:include href="./Summary.ptx"/>
9+
<xi:include href="./Exercises.ptx"/>
1010
</chapter>

0 commit comments

Comments
 (0)