So I'm completely new to Python and I've made only JS and PHP so far.
So I have this code
"""Shutdown code"""
timeToShutdown = input("Time to shutdown: ")
import os
os.system("shutdown /s /t %d") % timeToShutdown
It does not work like that (doesn't do anything),
It only works like this
"""Shutdown code"""
#timeToShutdown = input("Time to shutdown: ")
import os
os.system("shutdown /s /t 7200")
So what is wrong in inputting the number as variable.
PS: I've tried int(input())
too.
You have to format the string, not the return. ie, move your %
to inside the brackets:
os.system("shutdown /s /t %s" % timeToShutdown)
^ input() returns a string not a number
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.