math.gcd, lcm And prod On Integers

math.gcd reduces ratios, math.lcm finds the shared cadence of periodic jobs, and math.prod multiplies a list without an explicit reduce loop.

PythonData Integrity

Code

pythonsnippet
13 lines
import math

# gcd:把 1920x1080 化简成最简整数比
w, h = 1920, 1080
g = math.gcd(w, h)
print("aspect ratio:", w // g, ":", h // g)

# lcm:每 30 与每 45 分钟各跑一次的作业,共同的下次同步间隔
print("combined cadence:", math.lcm(30, 45), "minutes")

# prod:三组变体数的笛卡尔组合总数
variants = [3, 4, 5]
print("total variants:", math.prod(variants))

Output

Captured from a sandboxed run of this snippet in the build pipeline.

aspect ratio: 16 : 9
combined cadence: 90 minutes
total variants: 60

Inside the snippet

Top-level bindings variants hold the demo state — nothing sits inside a function scope.

Putting it to use

The demo output is labeled (aspect ratio:, combined cadence:, total variants:), so every printed line maps back to its originating operation.

Interactive Tools for This Topic

FAQ

Does the code pull in any external packages?
No external packages are involved; every call resolves to a built-in API. Its state lives in module-level bindings: `variants`.