You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
25
25
26
26
You can see and read this book online at `runestone.academy <http://runestone.academy/ns/books/published/thinkcspy/index.html?mode=browsing>`_
27
27
@@ -33,7 +33,7 @@ Building with PreTeXt
33
33
1. Create a virtual environment
34
34
2. pip install pretextbook
35
35
3. To build run: pretext build web
36
-
4. pretext view html
36
+
4. pretext view web
37
37
38
38
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.
39
39
@@ -50,16 +50,13 @@ Building a PDF
50
50
51
51
1. clone this repo
52
52
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.
57
54
58
55
59
56
Building with runestone
60
57
-----------------------
61
58
62
-
As mentioned above this method is deprecated, but will still work.
59
+
As mentioned above this method is deprecated, but will still work.
63
60
Any updates to this book should be made in PreTeXt NOT RST.
64
61
65
62
You can build it and host it yourself in just a few simple steps:
Copy file name to clipboardExpand all lines: pretext/ClassesDiggingDeeper/Fractions.ptx
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
on the top is called the numerator and the number on the bottom is called the denominator. Sometimes people use a slash
10
10
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
11
11
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
13
13
completely described by representing two integers. We can begin by implementing the <c>Fraction</c> class and the <c>__init__</c>
14
14
method which will allow the user to provide a numerator and a denominator for the fraction being created.</p>
<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>
6
7
<programlanguage="python">
7
8
<input>
@@ -228,7 +229,7 @@ print(final_time_int)
228
229
</li>
229
230
</ul>
230
231
</p>
231
-
</introduction>
232
+
</subsection>
232
233
<subsectionxml:id="debugging_parseerror">
233
234
<title>ParseError</title>
234
235
<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>
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
+
251
252
<programlanguage="python">
252
253
<input>
253
254
current_time_str = input("What is the current time (in hours 0-23)?")
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
+
282
283
<programlanguage="python">
283
284
<input>
284
285
current_time_str = input("What is the "current time" (in hours 0-23)?")
@@ -296,7 +297,7 @@ print(final_time_int)
296
297
</solution>
297
298
</exercise>
298
299
<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>
300
301
<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>
301
302
</subsection>
302
303
<subsectionxml:id="debugging_typeerror">
@@ -449,6 +450,7 @@ print(final_time_int)
449
450
</input>
450
451
</program>
451
452
<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>
452
454
<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>
0 commit comments