# For the Christmas tree, note that you can create a large number of # duplicates of a string by multiplying by a number. # For instance: 'ab'*4 yields: 'abababab' def ChristmasTree(treeChar,edgeChar,height): print ' '*height+treeChar for i in range(1,height): print ' '*(height-i)+edgeChar+treeChar*(2*i-1)+edgeChar for i in range(2): print ' '*(height-1)+treeChar*3 def perfectNumbers(maxn): from math import sqrt for i in range(2,maxn+1): ifPerfectPrint(i) # assume that n is a perfect number (it may not be) and prepare to # print it out if it is, but don't do it if it isn't def ifPerfectPrint(n): from math import sqrt factsum=1 s=str(n)+' = 1' sq=int(sqrt(n)) for i in range(2,sq+1): if n%i==0: factsum+=i+n/i s+=' + '+str(i)+' + '+str(n/i) if factsum==n: print s