我是Python的初学者,并试图找出错误以及如何修复这个简短的python代码:
from time import *
class Stopwatch:
def __init__(self):
self.reset()
def start(self):
if not self.running:
self.start_time = clock()
self.running = True
else:
print('Stopwatch already running')
def stop(self):
if self.running:
self.elapsed += clock() - self.start_time
self.running = False
else:
print('stopwatch not running')
def reset(self):
self.start_time = self.elapsed = 0
self.running = False
def elapsed(self):
if not self.running:
return self.elapsed
else:
print("stopwatch must be stopped")
return None
timer = Stopwatch()
timer.start()
sleep(2)
print('I am awake \n')
timer.stop()
print(timer.elapsed())
--->我得到这个错误说 TypeError:'float'对象不可调用 但为什么'浮'不可赎回? 谢谢你的帮助 霍华德