from time import clock import sys def fact(num): fact=1 mul=0 memory=0 while num>=1: fact=fact*num num-=1 mul+=1 memory=memory+sys.getsizeof(num)+sys.getsizeof(fact) return fact,mul-1,memory f=open("in1_1.txt","r") temp=[] memory=0 for row in f: temp=row.split(',') f.close() length = len(temp) memory=memory+sys.getsizeof(temp) f=open("out_1_1_1.txt","w") f=open("out_1_1_1.txt","a") for i in range(0,length,1): start=clock() factorial,multiply,mem=fact(int(temp[i])) time_taken=clock()-start memory=memory+mem+sys.getsizeof(i) f.write("\n Factorial " + temp[i] + " = " + str(factorial)) f.write("\n Time Taken = " + str(time_taken) + "seconds ") f.write("\n Multiply = " + str(multiply)) f.write("\nMemory used is: "+str(memory)+" Bytes") f.close()