mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
New == syntax
This commit is contained in:
parent
4d8e859e8f
commit
bdfcfccbe5
73 changed files with 419 additions and 391 deletions
|
@ -12,17 +12,17 @@ error = 'fact.error' # exception
|
|||
|
||||
def fact(n):
|
||||
if n < 1: raise error # fact() argument should be >= 1
|
||||
if n = 1: return [] # special case
|
||||
if n == 1: return [] # special case
|
||||
res = []
|
||||
# Treat even factors special, so we can use i = i+2 later
|
||||
while n%2 = 0:
|
||||
while n%2 == 0:
|
||||
res.append(2)
|
||||
n = n/2
|
||||
# Try odd numbers up to sqrt(n)
|
||||
limit = sqrt(n+1)
|
||||
i = 3
|
||||
while i <= limit:
|
||||
if n%i = 0:
|
||||
if n%i == 0:
|
||||
res.append(i)
|
||||
n = n/i
|
||||
limit = sqrt(n+1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue