0
我想让一个村民在4个选项中分配一个随机名称以及4个选项中的随机响应,但我一直得到“TypeError :只能拼接元组(而不是“STR”),以元组”时,我想打印的最终名称和响应Python 3 TypeError:只能将元组(不是“str”)连接到元组
def villager():
responses = ("Hi", "Are you a hero?", "Are you from this village?", "There has been a dark shadow cast across the village")
npcnamechoice = ("Talion", "Ratbag", "Mildreth", "Susan")
random.choice(npcnamechoice)
npcname = npcnamechoice + ": "
print(npcname + "Hello my name is " + npcname + "would you like to talk")
random.choice(responses)
print("Press y to talk to the villager")
if input() == "y":
print(npcname + responses)
else:
print(npcname + "Goodbye")
问题是你只能连接元组(不是“str”)到元组。 –
像错误说...'npcnamechoice +“:'',你不能添加一个字符串到一个元组 –
正如已经解释过的,这里是一个正在发生的例子。尝试一下:https://pastebin.com/U8XZfnSf – idjaw