![](/img/trans.png)
[英]My code gives a “TypeError: not all arguments converted during string formatting” what's wrong?
[英]What's wrong with my string formatting?
所以我對 Python 完全陌生,到目前為止我只制作了 JS 和 PHP。
所以我有這個代碼
"""Shutdown code"""
timeToShutdown = input("Time to shutdown: ")
import os
os.system("shutdown /s /t %d") % timeToShutdown
它不能那樣工作(不做任何事情),
它只能這樣工作
"""Shutdown code"""
#timeToShutdown = input("Time to shutdown: ")
import os
os.system("shutdown /s /t 7200")
那么輸入數字作為變量有什么問題。
PS:我也試過int(input())
。
您必須格式化字符串,而不是返回值。 即,將您的%
移到括號內:
os.system("shutdown /s /t %s" % timeToShutdown)
^ input() returns a string not a number
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.