import sys from time import clock try: input=open('in_1_10.txt','r+') output=open('out_30_1_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) start=clock() multiply=0 memory=memory+sys.getsizeof(multiply) temp=2 memory=memory+sys.getsizeof(temp) product=temp memory=memory+sys.getsizeof(product) for i in range(3,n+1,1): fact=0 for j in range(1,i+1): fact=fact+temp temp=fact product=product*fact multiply=multiply+1 memory=memory+sys.getsizeof(i) memory=memory+sys.getsizeof(j) memory=memory+sys.getsizeof(fact) time=str(clock()-start) if(n!=2): output.write(str(product)+"\nNo. of multiplications are: "+str(multiply)+"\nTime consumed is: "+time+" secs"+"\nMemory used is: "+str(memory)+" Bytes") elif n==2: output.write("2"+"\nNo. of multiplications are: "+"0"+"\nTime consumed is: "+time+" secs"+"\nMemory used is: "+str(memory)+" Bytes") else: output.write("1"+"\nNo. of multiplications are: "+"0"+"\nTime consumed is: "+time+" secs"+"\nMemory used is: "+str(memory)+" Bytes") input.close() output.close()