Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd695a7

Browse files
committed
Changed all the examples with ugly platform-dependent float output to use
numbers that display nicely after repr(). From much doctest experience with the same trick, I believe people find examples with simple fractions easier to understand too: they can usually check the results in their head, and so feel confident about what they're seeing. Not even I get a warm feeling from a result that looks like 70330.345024097141 ...
1 parent 0ba9e3a commit bd695a7

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

Doc/tut/tut.tex

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ \subsection{Numbers \label{numbers}}
426426
operands convert the integer operand to floating point:
427427

428428
\begin{verbatim}
429-
>>> 4 * 2.5 / 3.3
430-
3.0303030303030303
429+
>>> 3 * 3.75 / 1.5
430+
7.5
431431
>>> 7.0 / 2
432432
3.5
433433
\end{verbatim}
@@ -469,15 +469,18 @@ \subsection{Numbers \label{numbers}}
469469
magnitude (as a float) or \code{z.real} to get its real part.
470470

471471
\begin{verbatim}
472-
>>> a=1.5+0.5j
472+
>>> a=3.0+4.0j
473473
>>> float(a)
474474
Traceback (most recent call last):
475475
File "<stdin>", line 1, in ?
476476
TypeError: can't convert complex to float; use e.g. abs(z)
477477
>>> a.real
478-
1.5
479-
>>> abs(a)
480-
1.5811388300841898
478+
3.0
479+
>>> a.imag
480+
4.0
481+
>>> abs(a) # sqrt(a.real**2 + a.imag**2)
482+
5.0
483+
>>>
481484
\end{verbatim}
482485

483486
In interactive mode, the last printed expression is assigned to the
@@ -486,14 +489,15 @@ \subsection{Numbers \label{numbers}}
486489
example:
487490

488491
\begin{verbatim}
489-
>>> tax = 17.5 / 100
490-
>>> price = 3.50
492+
>>> tax = 12.5 / 100
493+
>>> price = 100.50
491494
>>> price * tax
492-
0.61249999999999993
495+
12.5625
493496
>>> price + _
494-
4.1124999999999998
497+
113.0625
495498
>>> round(_, 2)
496-
4.1100000000000003
499+
113.06
500+
>>>
497501
\end{verbatim}
498502

499503
This variable should be treated as read-only by the user. Don't
@@ -2609,24 +2613,24 @@ \section{Fancier Output Formatting \label{formatting}}
26092613
reverse quotes (\code{``}). Some examples:
26102614
26112615
\begin{verbatim}
2612-
>>> x = 10 * 3.14
2616+
>>> x = 10 * 3.25
26132617
>>> y = 200 * 200
26142618
>>> s = 'The value of x is ' + `x` + ', and y is ' + `y` + '...'
26152619
>>> print s
2616-
The value of x is 31.400000000000002, and y is 40000...
2620+
The value of x is 32.5, and y is 40000...
26172621
>>> # Reverse quotes work on other types besides numbers:
26182622
... p = [x, y]
26192623
>>> ps = repr(p)
26202624
>>> ps
2621-
'[31.400000000000002, 40000]'
2625+
'[32.5, 40000]'
26222626
>>> # Converting a string adds string quotes and backslashes:
26232627
... hello = 'hello, world\n'
26242628
>>> hellos = `hello`
26252629
>>> print hellos
26262630
'hello, world\n'
26272631
>>> # The argument of reverse quotes may be a tuple:
26282632
... `x, y, ('spam', 'eggs')`
2629-
"(31.400000000000002, 40000, ('spam', 'eggs'))"
2633+
"(32.5, 40000, ('spam', 'eggs'))"
26302634
\end{verbatim}
26312635
26322636
Here are two ways to write a table of squares and cubes:
@@ -3477,7 +3481,7 @@ \subsection{Class Objects \label{classObjects}}
34773481
... self.r = realpart
34783482
... self.i = imagpart
34793483
...
3480-
>>> x = Complex(3.0,-4.5)
3484+
>>> x = Complex(3.0, -4.5)
34813485
>>> x.r, x.i
34823486
(3.0, -4.5)
34833487
\end{verbatim}

0 commit comments

Comments
 (0)