import sys from time import clock def fib(n): a=0 b=1 counta=0 countn=1 while 1: c=a+b counta+=1 countn+=1 a=b b=c if countn==n: return c,counta """The following code is executed above the return statement to find the memory used by the code in this function. It was found to be 102 bytes. This will be added to the memory usage of main(). mem1=sys.getsizeof(countn)+sys.getsizeof(a)+sys.getsizeof(b)+sys.getsizeof(c) print mem1 """ def main(): star=clock() f=open("c:\inputs\in2_1.txt","r") f1=open("out_31_sec2_1.txt","w") temp=[] append=temp.append write=f1.write for r in f: for c in r.split(','): if c != (" "): append(c) p=int(temp[0])+1 for i in xrange(1,p): n=int(temp[i]) q,counta=fib(n) write("%d=%d\n" %(n,q)) counta+=1 f1.write("There are %d additions in the program." %counta) end=clock() write("\nTime taken by the program is : %f seconds" %(end-star)) mem=sys.getsizeof(f)+sys.getsizeof(f1)+sys.getsizeof(temp)+sys.getsizeof(append)+sys.getsizeof(write)+sys.getsizeof(r)+sys.getsizeof(p)+sys.getsizeof(i)+sys.getsizeof(n) write("\nMemory used by the program is : %d bytes." %mem) f1.close() main()