from time import clock import sys try: input=open('in2_10.txt','r+') output=open('out_30_2_10.txt','w') except IOError: print "The file does not exist" memory=0 for row in input: n=int(row) memory=memory+sys.getsizeof(n) if n==1: output.write(str("1")+"\nNo. of additions are: "+str("0")+"\nNo. of multiplications are: "+str("0")+"\nTime consumed is: "+time+" secs") elif n==2: output.write(str("2")+"\nNo. of additions are: "+str("1")+"\nNo. of multiplications are: "+str("0")+"\nTime consumed is: "+time+" secs") else: start=clock() add=0 list=[1,1] for i in range(2,n): list.append(list[i-1]+list[i-2]) add=add+1 memory=memory+sys.getsizeof(list)+sys.getsizeof(add) time=str(clock()-start) product=1 multiply=0 for i in range(2,n): product=product*list[i] multiply=multiply+1 memory=memory+sys.getsizeof(product)+sys.getsizeof(multiply) output.write(str(product)+"\nNo. of additions are: "+str(add)+"\nNo. of multiplications are: "+str(multiply)+"\nTime consumed is: "+time+" secs"+"\nMemory used is: "+str(memory)+" Bytes") input.close() output.close()