写一个秒表测试台
时间: 2023-10-09 20:13:37 浏览: 190
秒表测试工具
以下是一个简单的秒表测试台,可以开始、停止和重置秒表,并记录时间:
```python
import time
def start_stopwatch():
start_time = time.time()
return start_time
def stop_stopwatch(start_time):
elapsed_time = time.time() - start_time
return elapsed_time
def reset_stopwatch():
return 0
elapsed_time = 0
is_running = False
while True:
command = input("Enter command (start, stop, reset, quit): ")
if command == "start":
if not is_running:
start_time = start_stopwatch()
is_running = True
print("Stopwatch started.")
else:
print("Stopwatch is already running.")
elif command == "stop":
if is_running:
elapsed_time += stop_stopwatch(start_time)
is_running = False
print("Stopwatch stopped.")
else:
print("Stopwatch is not running.")
elif command == "reset":
elapsed_time = reset_stopwatch()
is_running = False
print("Stopwatch reset.")
elif command == "quit":
break
else:
print("Invalid command.")
print("Elapsed time: %.2f seconds" % elapsed_time)
```
阅读全文