Skip to content

Commit 68f544c

Browse files
CouldNotsedatguzelsemme
authored andcommitted
Expand euler phi function doctest (TheAlgorithms#10401)
1 parent a2bfbda commit 68f544c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Diff for: maths/basic_maths.py

+10
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,17 @@ def euler_phi(n: int) -> int:
9898
"""Calculate Euler's Phi Function.
9999
>>> euler_phi(100)
100100
40
101+
>>> euler_phi(0)
102+
Traceback (most recent call last):
103+
...
104+
ValueError: Only positive numbers are accepted
105+
>>> euler_phi(-10)
106+
Traceback (most recent call last):
107+
...
108+
ValueError: Only positive numbers are accepted
101109
"""
110+
if n <= 0:
111+
raise ValueError("Only positive numbers are accepted")
102112
s = n
103113
for x in set(prime_factors(n)):
104114
s *= (x - 1) / x

0 commit comments

Comments
 (0)