python3typeerror:只能将tuple(而不是“str”)连接到tup

2024-10-01 13:42:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我想让一个村民从4个选项中随机分配一个名字,以及从4个选项中随机选择一个答案,但是当我想打印最后的名字和答案时,我总是得到“TypeError:can oncatenate tuple(not”str“)to tuple”

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")

Tags: theto答案you选项randomresponses名字