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
Copy file name to clipboardExpand all lines: source/ch4_conditionals.ptx
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -261,7 +261,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
261
261
<title>Exception Handling</title>
262
262
263
263
<p>
264
-
In Python, if you want a program to continue running when an error has occurred, you can use <c>try-except</c> blocks to handle exceptions. If you wanted to write a program that asks the user to enter a whole number and then squares that number, you could use the following code to do so:
264
+
In Python, if you want a program to continue running when an error has occurred, you can use <c>try-except</c> blocks to handle exceptions. If you wanted to write a program that asks the user to enter a whole number and then squares that number, you could use the following code to do so. <xrefref="python-square-input"text="type-global"/> shows the Python code to achieve this.
265
265
</p>
266
266
267
267
<listingxml:id="python-square-input">
@@ -275,7 +275,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
275
275
</listing>
276
276
277
277
<p>
278
-
The Java code that would perform the same task is a little more complex and utilizes the <c>Scanner</c> class for input.
278
+
<xrefref="java-square-input"text="type-global"/> shows the Java code that would perform the same task. It is a little more complex and utilizes the <c>Scanner</c> class for input.
279
279
</p>
280
280
<listingxml:id="java-square-input">
281
281
<programinteractive="activecode"language="java">
@@ -298,7 +298,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
298
298
</listing>
299
299
300
300
<p>
301
-
This code works well, but will end with an exception if the user types anything other than a whole number (such as 12.5 or two). If we wanted to ensure the code will continue to run until the user enters the correct format, we could add <c>try-except</c> (Python) or <c>try-catch</c> (Java) blocks within a <c>while</c> loop that iterates until the user enter the correct code. Adding <c>try-except</c> blocks and a <c>while</c> loop to the Python code will look something like this:
301
+
This code works well, but will end with an exception if the user types anything other than a whole number (such as 12.5 or two). If we wanted to ensure the code will continue to run until the user enters the correct format, we could add <c>try-except</c> (Python) or <c>try-catch</c> (Java) blocks within a <c>while</c> loop that iterates until the user enter the correct code. <xrefref="python-square-input-exception"text="type-global"/> shows how adding <c>try-except</c> blocks and a <c>while</c> loop to the Python code will look.
@@ -316,7 +316,7 @@ The <c>switch</c> statement is not used very often, and we recommend you do not
316
316
</listing>
317
317
318
318
<p>
319
-
Now that we have Python code that will continuously prompt the user until they enter a whole number, let's look at Java code that accomplishes the same task. Like most other equivalent Java code blocks, this code has a lot of extra bits that are necessary to get working code.
319
+
Now that we have Python code that will continuously prompt the user until they enter a whole number, <xrefref="java-square-input-exception"text="type-global"/> shows the Java code that accomplishes the same task. Like most other equivalent Java code blocks, this code has a lot of extra bits that are necessary to get working code.
0 commit comments