From 2bd13ddc1a0594b039710e4713d796232f039068 Mon Sep 17 00:00:00 2001 From: "Lyekluo." <132440008+Lyekluo@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:07:46 +0800 Subject: [PATCH] Line 136: corrected to ">>> from math import gcd" for Python 3.9+ In Python 3.9+, gcd was removed from the fractions module and moved to the built-in math module. The current code would raise an ImportError. This pull request updates Line 136 to use math.gcd to ensure the code runs correctly on Python 3.9 and above. --- sicp/2/2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sicp/2/2.md b/sicp/2/2.md index 0028d62..dbd8fc4 100644 --- a/sicp/2/2.md +++ b/sicp/2/2.md @@ -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)