Discuss / Python / 交作业, 但是有没有哪位大神能告诉我以下, 为什么打印时间是10.24?

交作业, 但是有没有哪位大神能告诉我以下, 为什么打印时间是10.24?

Topic source
import time, functoolsdef decorator(func):    @functools.wraps(func)    def wrapper(*args, **kwargs):        print('%s executed in %s ms' % (func.__name__, 10.24))        return func(*args, **kwargs)    return wrapper@decoratordef fast(x, y):    time.sleep(0.0012)    return x + y;@decoratordef slow(x, y, z):    time.sleep(0.1234)    return x * y * z;f = fast(11, 22)s = slow(11, 22, 33)if f != 33:    print('测试失败!')elif s != 7986:    print('测试失败!')
def wrapper(*args, **kwargs):   
  print('%s executed in %s ms' % (func.__name__, 10.24))        
  return func(*args, **kwargs)    

你自己在程序里写的10.24,OK?

print()函数中前面部分是要格式化输出的语句,%后面括号中是要代入的参数,OK?

别人写10.30是乐意,正经按照题意来写的话应该用执行函数前后时间差,就是

t1 = time.time()

result = func(*args, **kw)

t2 = time.time()

print( t2 - t1 )

return result


  • 1

Reply