它给的答案里def __init__(self, num):
a, b, L = 0, 1, []
for n in range(num):
应该是def __init__(self, num):
a, b, L = 0, 1, []
for n in range(num+1):
如果没有+1会少一个
a, b, L = 0, 1, []
for n in range(num):
应该是def __init__(self, num):
a, b, L = 0, 1, []
for n in range(num+1):
如果没有+1会少一个
2015-04-29
def gcd(a,b):
if max(a,b)%min(a,b)==0:
return min(a,b)
else:
return gcd(min(a,b),max(a,b)%min(a,b))
if max(a,b)%min(a,b)==0:
return min(a,b)
else:
return gcd(min(a,b),max(a,b)%min(a,b))
2015-04-28
class Fib(object):
def __init__(self, num):
self.nums=[]
if num==1:
self.nums=[1]
else :
n=2
self.nums=[1,2]
while n<num:
self.nums.append(self.nums[n-1]+self.nums[n-2])
n=n+1
def __init__(self, num):
self.nums=[]
if num==1:
self.nums=[1]
else :
n=2
self.nums=[1,2]
while n<num:
self.nums.append(self.nums[n-1]+self.nums[n-2])
n=n+1
2015-04-28
import math
def is_sqr(x):
if math.sqrt(x) in range(1,11):
return x
print filter(is_sqr, range(1,101))
def is_sqr(x):
if math.sqrt(x) in range(1,11):
return x
print filter(is_sqr, range(1,101))
2015-04-27
def cmp_ignore_case(s1, s2):
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
return 0
if s1.lower()>s2.lower():
return 1
if s1.lower()<s2.lower():
return -1
return 0
2015-04-26