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

Skip to content

Commit 5a55b61

Browse files
committed
Issue #6354: More fixes for code examples involving the repr of a float.
1 parent 6e6565b commit 5a55b61

6 files changed

Lines changed: 13 additions & 13 deletions

File tree

Doc/library/math.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Number-theoretic and representation functions
8282
loss of precision by tracking multiple intermediate partial sums::
8383

8484
>>> sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
85-
0.99999999999999989
85+
0.9999999999999999
8686
>>> fsum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
8787
1.0
8888

Doc/library/sqlite3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ This example uses the iterator form::
8181
>>> for row in c:
8282
... print(row)
8383
...
84-
(u'2006-01-05', u'BUY', u'RHAT', 100, 35.140000000000001)
84+
(u'2006-01-05', u'BUY', u'RHAT', 100, 35.14)
8585
(u'2006-03-28', u'BUY', u'IBM', 1000, 45.0)
8686
(u'2006-04-06', u'SELL', u'IBM', 500, 53.0)
8787
(u'2006-04-05', u'BUY', u'MSOFT', 1000, 72.0)
@@ -591,7 +591,7 @@ Now we plug :class:`Row` in::
591591
>>> type(r)
592592
<type 'sqlite3.Row'>
593593
>>> r
594-
(u'2006-01-05', u'BUY', u'RHAT', 100.0, 35.140000000000001)
594+
(u'2006-01-05', u'BUY', u'RHAT', 100.0, 35.14)
595595
>>> len(r)
596596
5
597597
>>> r[2]

Doc/library/turtle.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ Color control
881881
>>> tup = (0.2, 0.8, 0.55)
882882
>>> turtle.pencolor(tup)
883883
>>> turtle.pencolor()
884-
(0.20000000000000001, 0.80000000000000004, 0.5490196078431373)
884+
(0.2, 0.8, 0.5490196078431373)
885885
>>> colormode(255)
886886
>>> turtle.pencolor()
887887
(51, 204, 140)

Doc/tutorial/inputoutput.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ Some examples::
5252
'Hello, world.'
5353
>>> repr(s)
5454
"'Hello, world.'"
55-
>>> str(0.1)
56-
'0.1'
57-
>>> repr(0.1)
58-
'0.10000000000000001'
55+
>>> str(1.0/7.0)
56+
'0.142857142857'
57+
>>> repr(1.0/7.0)
58+
'0.14285714285714285'
5959
>>> x = 10 * 3.25
6060
>>> y = 200 * 200
6161
>>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...'

Doc/tutorial/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ operators ``+``, ``-``, ``*`` and ``/`` work just like in most other languages
5656
>>> (50-5*6)/4
5757
5.0
5858
>>> 8/5 # Fractions aren't lost when dividing integers
59-
1.6000000000000001
59+
1.6
6060

6161
Note: You might not see exactly the same result; floating point results can
6262
differ from one machine to another. We will say more later about controlling

Doc/tutorial/stdlib2.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@ results in decimal floating point and binary floating point. The difference
359359
becomes significant if the results are rounded to the nearest cent::
360360

361361
>>> from decimal import *
362-
>>> Decimal('0.70') * Decimal('1.05')
363-
Decimal("0.7350")
364-
>>> .70 * 1.05
365-
0.73499999999999999
362+
>>> round(Decimal('0.70') * Decimal('1.05'), 2)
363+
Decimal('0.74')
364+
>>> round(.70 * 1.05, 2)
365+
0.73
366366

367367
The :class:`Decimal` result keeps a trailing zero, automatically inferring four
368368
place significance from multiplicands with two place significance. Decimal

0 commit comments

Comments
 (0)