2016-12-23 88 views
-2

我目前正在做一個文本遊戲,但我的遊戲的一部分將無法正常工作,我不明白爲什麼。這是編碼:糟糕的一元操作數顯然

c1pp1 = ["Joe", "Frank", "Annie"] 

while cp_ptt < 3: 
     s= input() 
     #FIX THIS!! 
     c1pp = input(n/ + ": Who should I talk to first?\nYour options are:\n" +\ 
       c1pp1[0] + ", an ex-policeman\n" + c1pp1[1] + ", a carpenter\n" +\ 
       c1pp1[2] + ", an architect\n") 

我得到的結果是:

Traceback (most recent call last): 
File "N:\MyWork\Year 9\Other\Random\Making a text game out of song lyrics\No.1; 
Phantom Thief F's Scenario ~Mystery of the Missing Diamond~.py", line 103, 
in <module> 
c1pp = input(n/ + ": Who should I talk to first?\nYour options are:\n" + c1pp1[0] + ", an ex-policeman\n" + c1pp1[1] + ", a carpenter\n" + c1pp1[2] + ", an architect\n") 
TypeError: bad operand type for unary +: 'str' 

是否有人可以告訴我什麼是錯我的代碼?

+10

這是'n /'一個錯字嗎?這顯然是這樣的問題。你想用這個做什麼? –

+0

@CarlesMitjans錯誤將會是'NameError:name'n'未定義'。 – DyZ

+0

問題是:爲什麼那裏有'n'?這是一個變量還是您嘗試打印換行符? –

回答

0

突出顯示錶達式的一些括號將有所幫助。

您的代碼試圖解析n/(+ ": Who should I talk to first?\nYour options are:\n"),但+ "any string"不是有效使用的一元運算符+

和其他人一樣,在評論中指出,你可能犯了一個錯字。沒有剩下的代碼,我不能告訴你你需要做什麼來獲得你想要的輸出,但是你可以先刪除那個/