import time
listy = ['timer','stopwatch']
def intro():
print("This is a program which contains useful tools")
print(listy)
def timer():
x = int(input("How long Seconds ?"))
while x > 0:
print(x)
time.sleep(1)
x -= 1
def stopwatch():
verif = input("Do you want to start y/n \n")
if verif == 'y':
x = 0
while True:
print(x, end = "\b"*5)
time.sleep(1)
x += 1
def main():
intro()
decider = input("Which Program?")
if decider.lower() == 'timer':
timer()
elif decider.lower() == 'stopwatch':
stopwatch()
main()
在这段代码中我不知道为什么\ b转义序列不能在cmd或空闲时工作,有人可以解释为什么吗?是因为逻辑错误吗?
答案 0 :(得分:0)
可能需要同花。怎么样......
print("{0}{1}".format("\b"*5, x), end="", flush=True)