显示关机前剩余的时间

display how much time is left until shutdown

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

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

添加一个display_time变量,然后检查run % display_time == 0:

import time as t
import os

print("Timed Shutdown")
run = int(input("Please enter a shutdown time in minutes: "))
run *= 60
display_time = 60 # number of seconds between displays
while run != 0:
    run -= 1
    t.sleep(1)
    if run % display_time == 0:
        print("Your system willl close in:", str(int(run/60)), "minutes")
print("hi")
# os.system("shutdown -s")
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的倍数,则打印剩余时间。