Skip to content

Commit 5d01328

Browse files
committed
added listing to text
1 parent ff92dab commit 5d01328

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

source/ch7_recursion.ptx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
as <m>n \times (n-1)!</m>.
3535
</p>
3636
<p>
37-
Here is a Python implementation of factorial using just one function:
37+
<xref ref="factorial-python-function" text="type-global"/> is the Python implementation of the factorial function. It checks for negative numbers, defines the base case for 0! and 1!, and implements the recursive step.
3838
</p>
3939
<listing xml:id="factorial-python-function">
4040
<program interactive="activecode" language="python">
@@ -60,6 +60,10 @@ print(str(number) + "! is " + str(factorial(number)))
6060
<p>
6161
Many Python programs organize related functions into classes. The same factorial function can be placed inside a class as a method instead of as a function. When this is done, you need to create an instance of the class in order to call the method. Below, we create the class <c>MathTools</c> with a method <c>factorial</c>, and we call it from the <c>main</c> function.
6262
</p>
63+
<p>
64+
<xref ref="factorial-python-class" text="type-global"/> is the Python implementation of the factorial function as a method within a class. It maintains the same logic as the previous function but is now encapsulated within a class structure.
65+
</p>
66+
6367
<listing xml:id="factorial-python-class">
6468
<program interactive="activecode" language="python">
6569
<code>
@@ -90,7 +94,7 @@ main()
9094
See if you can spot the differences in the Java version below.
9195
</p>
9296
<p>
93-
Here is the equivalent Java code:
97+
<xref ref="factorial-java-class" text="type-global"/> is the Java implementation of the factorial function. It follows the same logic as the Python version but adapts to Java's syntax and type system.
9498
</p>
9599
<listing xml:id="factorial-java-class">
96100
<program interactive="activecode" language="java">

0 commit comments

Comments
 (0)