Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sicp/2/2.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Python 中的列表(以及大多数其他编程语言中的序列)都是 **0
如上面的例子所示,我们的有理数实现没有把有理数化简成**最简分数**(lowest terms)。要弥补这个缺陷,可以修改 `rational` 的实现。如果我们有一个计算两个整数最大公约数的函数,就能在构造「对」之前,先把分子和分母化简。和许多好用的工具一样,这样的函数 Python 标准库里早就有了。

```py
>>> from fractions import gcd
>>> from math import gcd
>>> def rational(n, d):
g = gcd(n, d)
return (n//g, d//g)
Expand Down
Loading