From 9fb0cd271efec0fc651a5143aedda42f3dc93ea8 Mon Sep 17 00:00:00 2001 From: Dale Dai <145884899+CouldNot@users.noreply.github.com> Date: Fri, 13 Oct 2023 23:47:08 -0700 Subject: [PATCH] Expand euler phi function doctest (#10401) --- maths/basic_maths.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/maths/basic_maths.py b/maths/basic_maths.py index 26c52c549..c9e3d00fa 100644 --- a/maths/basic_maths.py +++ b/maths/basic_maths.py @@ -98,7 +98,17 @@ def euler_phi(n: int) -> int: """Calculate Euler's Phi Function. >>> euler_phi(100) 40 + >>> euler_phi(0) + Traceback (most recent call last): + ... + ValueError: Only positive numbers are accepted + >>> euler_phi(-10) + Traceback (most recent call last): + ... + ValueError: Only positive numbers are accepted """ + if n <= 0: + raise ValueError("Only positive numbers are accepted") s = n for x in set(prime_factors(n)): s *= (x - 1) / x