-2
我有一些代碼,但我不明白它爲什麼說類型錯誤。該代碼是:類型錯誤不允許我運行遊戲聲納
if sonarDevices > 1: extraSsonar = 's'
else: extraSsonar = ' '
if len(theChests) > 1: extraSchest = 's'
else: extraSchest = 's'
print('You have %s sonar devices left. %s treasure chest%s remaining' % (sonarDevices, extraSsonar, len(theChests), extraSchest))
的錯誤是:( '你必須離開%s的聲納裝置%s的百寶箱%S剩餘' %(sonarDevices,extraSsonar,LEN(theChests),extraSchest)) 打印 TypeError:並非在字符串格式化期間轉換的所有參數
「在字符串格式化過程中轉換的所有參數」是什麼意思?
4個參數,只有3個'%s':這就是問題所在。 –