我想让一个村民从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")
你没有捕捉到随机值。它本身,只是调用函数,它没有重新分配
npcnamechoice
所以,创建另一个变量,或者内联它
^{pr2}$对回答也一样
相关问题 更多 >
编程相关推荐