我无法让我的倒计时在python中工作
我遵循了一个创建倒计时计时器的步骤。但我在以下代码中不断遇到错误:我无法让我的倒计时在python中工作,python,pycharm,Python,Pycharm,我遵循了一个创建倒计时计时器的步骤。但我在以下代码中不断遇到错误: import time while True: uin = input(">>") try: when_to_stop = abs(int(uin)) except KeyboardInterrupt: break except: print("not a number mate") while when_to_stop &g
import time
while True:
uin = input(">>")
try:
when_to_stop = abs(int(uin))
except KeyboardInterrupt:
break
except:
print("not a number mate")
while when_to_stop > 0:
m, s = divmod(when_to_stop, 60)
h, m = divmod(m, 60)
time_left = str(h).zfill(2) + ":" + str(m).zfill(2) + ":" + str(s).zfill(2)
print (time_left + "\r", end="")
time.sleep(1)
when_to_stop -= 1
print()
我得到了一个我的编辑器(pycharm)无法识别的错误(end=“”)
有人能帮我解决我做错了什么吗?end=”“
是在python 3中添加的。如果它导致了错误,那么您可能正在运行Python3下的python版本。(例如python 2.x)
只需替换:-
print (time_left + "\r", end="")
作者:-
听起来您是在运行python 2时编写python 3代码的。谢谢,我怀疑这就是问题所在。我也去掉了“\r”,它现在可以工作了,它不会覆盖自身,但我可以接受。
print (time_left + "\r")