from sympy import * import time import datetime for i in range(1,50): print('第'+str(i)+'次计算开始') x = Symbol('x') startTime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()) print(startTime) mystr='' for j in range(1,i+1): mystr+='+x**'+str(j) mystr=mystr[1:] xx=solve(eval(mystr)-1.1*i,x) endTime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()) print(endTime) startTime= datetime.datetime.strptime(startTime,"%Y-%m-%d %H:%M:%S") endTime= datetime.datetime.strptime(endTime,"%Y-%m-%d %H:%M:%S") seconds = (endTime- startTime).seconds print('第{}次方方程计算耗费的时间为{}秒'.format(i,seconds))