2017-02-12 15 views
-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:並非在字符串格式化期間轉換的所有參數

「在字符串格式化過程中轉換的所有參數」是什麼意思?

+1

4個參數,只有3個'%s':這就是問題所在。 –

回答

0

在字符串中有三個佔位符,但元組中有四個項目。

0

添加到丹尼爾說,你也傳遞一個整數%s。使用%d作爲數字的佔位符。