首页 > 解决方案 > 显示距离关机还有多长时间

问题描述

import time as t
import os

print("Timed Shutdown")
run = int(input("Please enter a shutdown time in minutes: "))
run *= 60
while run != 0:
    run -= 1
    t.sleep(1)
    print("Your system willl close in:", str(int(run/60)), "minutes")

os.system("shutdown -s")

我正在尝试制作一个程序,在用户以分钟为单位输入特定时间后关闭计算机。我想从 while 循环内部制作打印语句,以便用户仅在一分钟过去后(或t一段时间后)才能看到。

标签: python-3.xtimeos.system

解决方案


import time as t
import os

interval = 30
print("Timed Shutdown")
run = int(input("Please enter a shutdown time in minutes: "))
run *= 60
while run != 0:
    run -= 1
    t.sleep(1)
    if run % interval == 0:
        print("Your system will close in:", str(int(run/60)), "minutes")

os.system("shutdown -s")

如果剩余时间是剩余时间的倍数,interval将被打印。


推荐阅读