python-3.x - 显示距离关机还有多长时间
问题描述
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
一段时间后)才能看到。
解决方案
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
将被打印。
推荐阅读
- html - 使用图像绝对位置时使整个选择可点击
- javascript - NodeJS:无效的数组长度分配失败 - JavaScript 堆内存不足
- python - 仅在 MongoDB 中返回匹配的属性
- javascript - 如何重定向顶级路由而不是子路由?
- python - Flask UnitTests 访问错误的 URI
- php - 了解 wordpress 的权限
- laravel - 迁移和模型之间有什么关系?
- saxon - Saxon 是否提供了一种方法来维护地图中键的插入顺序?
- java - 如何在 cognito 中使用 adminGetUserRequest 获取用户属性
- pandas - iloc 的功能和简单的 [ ] 系列