我无法倒数在python中工作

时间:2019-06-29 01:32:48

标签: python pycharm

我遵循youtube video创建倒数计时器。但是我在以下代码中不断收到错误:

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()

我收到一个错误my editor (pycharm) doesn't recognise (end="")

有人可以帮我解决我做错的事情吗?

1 个答案:

答案 0 :(得分:1)

end=""已添加到python 3中。如果引起错误,则可能是您在python 3下运行了python版本(例如python 2.x)

只需替换:-

print (time_left + "\r", end="")

通过:-

print (time_left + "\r")