def stairs(n):
return (n==1 or n==2) and 1 or (stairs(n-1)+stairs(n-2))
print(stairs(3))
- read more
43.The Fibonacci sequence
read morea=[1,1] for i in range(2,n): a.append(a[i-2]+a[i-1]) print a[n-1]%20132013
42.Splitting the prime Numbers sum
read moren=10 def isPrime(n): if n <= 1: return False for i in range(2, n): if n % i == 0: return False return True count = 0 for i in range(2,n): if isPrime(i) and isPrime(n-i): count += 1 print count/2
41.Py
read moren=2992 def py(n,m): total = 0 while n>0: total+=n%m n=n/m return total print py(n,10)==py(n,16)==py(n,12) and "Yes" or "No"
40.Integer solutions
read morea=8 b=15 x=a ** 2 - 4 * b print x>=0 and x**0.5==int(x**0.5) and "YES" or "NO"
38.Simple list of conversion
read moreL=['abc','d','efg'] print "".join([x for x in L])
37.pythagorean theorem
read morea=3 b=4 print "%.3f" % (a**2+b**2)**0.5
36.Maximum not continuous subsequence
read moreL = [2, -3, 3, 50] for i in range(2,len(L)): L[i]=(max(max(L[0:i-1]),0)+L[i]) print max(L)
35.Maximum continuous subsequence
read moremaxim=0 sum=0 for i in range(len(L)): if L[i]<0: maxim=max(sum,maxim) sum=0 else: sum+=L[i] print max(sum,maxim) # don't forget the last one
34.The password generated
read morea = 1 b = 77 x = 1 y = 14 lister, ans, a = [], [], a%b*10 while a not in lister: lister.append(a) # 1. not includes x of x.123456 ans.append(a // b) a = (a % b)*10 nolooplen = lister.index(a) # when the iteration appears in ans looplen = len(ans ...