我目前正在制作文字游戏,但我游戏的一部分不起作用,我无法弄清楚原因。这是编码:
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'
有人可以告诉我我的代码有什么问题吗?
答案 0 :(得分:1)
突出显示表达式的一些括号将有所帮助。
您的代码正在尝试解析n / (+ ": Who should I talk to first?\nYour options are:\n")
,但+ "any string"
不能正确使用一元+
运算符。
正如其他人在评论中指出的那样,你可能犯过一个错字。如果没有剩下的代码,我无法告诉您需要做什么来获得所需的输出,但您可以从删除/
开始。