Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用输入功能指定关机时间_Python - Fatal编程技术网

Python 使用输入功能指定关机时间

Python 使用输入功能指定关机时间,python,Python,编辑脚本以使用input()函数向用户查询关机超时时间。编辑脚本以使用另一个input()函数查询用户,以在机器执行关机时显示消息。我在使用输入功能询问用户关机时间以及询问他们显示消息时遇到问题 import os #chkdsk = "chkdsk C:" #os.system(chkdsk) print("How much time till shutdown?") time = input() print (time) shutdown = 'shutdown", "-f", "-

编辑脚本以使用input()函数向用户查询关机超时时间。编辑脚本以使用另一个input()函数查询用户,以在机器执行关机时显示消息。我在使用输入功能询问用户关机时间以及询问他们显示消息时遇到问题

import os

#chkdsk = "chkdsk C:"
#os.system(chkdsk)

print("How much time till shutdown?")
time = input() 
print (time)

shutdown = 'shutdown", "-f", "-r", "-t", "-c", MESSAGE HERE'
os.system(shutdown)

我理解正确吗:你想把时间放在字符串中吗

shutdown = 'shutdown -f -r -t {time} -c MESSAGE HERE'
os.system(shutdown.format(time=time))

您只需使用该行:

x = int(input("How much time till shutdown?"))

我在使用输入函数时遇到问题。。。什么具体问题?(提示:您应该将此信息包括在问题本身以及您可能在此处提出的所有未来问题中。)FWIW,您应该将输入提示作为参数传递给
input
函数,而不是使用
print
。顺便说一句,您缺少一个
关闭前<代码>关闭。您不应该使用
time
作为变量名,因为这是标准模块的名称。将其用作变量名会使代码难以阅读。是的。我想询问用户一段时间,然后将其插入shutdown命令。是。我尝试了你的代码,但仍然没有正确执行。输入时间和消息输入后,弹出关机帮助页面。