2014-04-04 112 views
1

我遇到了編寫代碼字遊戲(也稱爲替換字符)程序的問題,並且不斷收到錯誤'str '對象不可調用。這是我的代碼(while循環它涉及到這本字典的只是一部分:TypeError:'str'對象不可打印,用於在while循環內打印字典

used_pairings = {} 

while.....: 
    used_pairings[guesschar] = guessletter 
    print = ("At this point you can decide whether to delete a character-letter pairing.") 
    used_pairings_choice = input("Type 1 to delete a pairing or ENTER to carry on: ") 
    if used_pairings_choice == "1": 
     print ("These are your pairings so far:") 
     print (used_pairings) 
    else: 
     print ("Continuing program.") 

這是我的錯誤:

"Codeword.py", line 79, in <module> 
    print ("These are your pairings so far:") 
TypeError: 'str' object not callable 

我在賠率完全是爲了這意味着什麼爲什麼我收到此錯誤消息,所以任何幫助,將不勝感激。在此先感謝!

+0

這是蟒蛇2還是3? 'while .......'是怎麼回事? – Holloway

+0

這是蟒蛇3.3.3和while ....是其中的替換字符發生的事情(這完美的作品)的程序的其餘部分 – lemurofawesomeness

+1

錯誤的三個致命錯誤?我們有一個密切的原因,請使用它... – l4mpi

回答

5

如果您使用python 3+ print是一項功能。當你做print = ("At this point you can decide whether to delete a character-letter pairing.")時,你用一個字符串覆蓋了內建函數print。因此,從該行刪除=應該修復它。

1

的問題是,print變量聲明。

print = ("At this point you can decide whether to delete a character-letter pairing.") 

此聲明之後print Python的函數變爲print變量str(STRING)。

請更改變量名稱並嘗試您的代碼。

+0

爲什麼我這樣做,呃? – lemurofawesomeness

+0

非常感謝你們所提出的改變。 – lemurofawesomeness