mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +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)
|
||||
|
|
|
@ -24,13 +24,13 @@ except RuntimeError:
|
|||
while 1:
|
||||
line = mail.readline()
|
||||
if not line: break # EOF
|
||||
if line[:5] = 'From ':
|
||||
if line[:5] == 'From ':
|
||||
# Start of message found
|
||||
print line[:-1],
|
||||
while 1:
|
||||
line = mail.readline()
|
||||
if not line: break # EOF
|
||||
if line = '\n': break # Blank line ends headers
|
||||
if line[:8] = 'Subject:':
|
||||
if line == '\n': break # Blank line ends headers
|
||||
if line[:8] == 'Subject:':
|
||||
print `line[9:-1]`,
|
||||
print
|
||||
|
|
|
@ -23,7 +23,7 @@ def main():
|
|||
# Strip '-P' from printer names just in case
|
||||
# the user specified it...
|
||||
for i in range(len(printers)):
|
||||
if printers[i][:2] = '-P':
|
||||
if printers[i][:2] == '-P':
|
||||
printers[i] = printers[i][2:]
|
||||
else:
|
||||
if posix.environ.has_key('PRINTER'):
|
||||
|
@ -54,13 +54,13 @@ def makestatus(name, thisuser):
|
|||
if not line: break
|
||||
fields = string.split(line)
|
||||
n = len(fields)
|
||||
if len(fields) >= 6 and fields[n-1] = 'bytes':
|
||||
if len(fields) >= 6 and fields[n-1] == 'bytes':
|
||||
rank = fields[0]
|
||||
user = fields[1]
|
||||
job = fields[2]
|
||||
files = fields[3:-2]
|
||||
bytes = eval(fields[n-2])
|
||||
if user = thisuser:
|
||||
if user == thisuser:
|
||||
userseen = 1
|
||||
elif not userseen:
|
||||
aheadbytes = aheadbytes + bytes
|
||||
|
@ -77,9 +77,9 @@ def makestatus(name, thisuser):
|
|||
else:
|
||||
if fields and fields[0] <> 'Rank':
|
||||
line = string.strip(line)
|
||||
if line = 'no entries':
|
||||
if line == 'no entries':
|
||||
line = name + ': idle'
|
||||
elif line[-22:] = ' is ready and printing':
|
||||
elif line[-22:] == ' is ready and printing':
|
||||
line = name
|
||||
lines.append(line)
|
||||
#
|
||||
|
@ -87,12 +87,12 @@ def makestatus(name, thisuser):
|
|||
line = `(totalbytes+1023)/1024` + ' K'
|
||||
if totaljobs <> len(users):
|
||||
line = line + ' (' + `totaljobs` + ' jobs)'
|
||||
if len(users) = 1:
|
||||
if len(users) == 1:
|
||||
line = line + ' for ' + users.keys()[0]
|
||||
else:
|
||||
line = line + ' for ' + `len(users)` + ' users'
|
||||
if userseen:
|
||||
if aheadjobs = 0:
|
||||
if aheadjobs == 0:
|
||||
line = line + ' (' + thisuser + ' first)'
|
||||
else:
|
||||
line = line + ' (' + `(aheadbytes+1023)/1024`
|
||||
|
|
|
@ -19,7 +19,7 @@ def main():
|
|||
# Print common digits
|
||||
d, d1 = a/b, a1/b1
|
||||
#print a, b, a1, b1
|
||||
while d = d1:
|
||||
while d == d1:
|
||||
# Use write() to avoid spaces between the digits
|
||||
sys.stdout.write(`int(d)`)
|
||||
# Flush so the output is seen immediately
|
||||
|
|
|
@ -17,7 +17,7 @@ def primes(min, max):
|
|||
i = 3
|
||||
while i <= max:
|
||||
for p in primes:
|
||||
if i%p = 0 or p*p > i: break
|
||||
if i%p == 0 or p*p > i: break
|
||||
if i%p <> 0:
|
||||
primes.append(i)
|
||||
if i >= min: print i
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue