gpt4 book ai didi

python - 根据其他列表从列表中选择

转载 作者:太空宇宙 更新时间:2023-11-03 21:39:49 24 4
gpt4 key购买 nike

我正在尝试制作一个可以为游戏中的下一个角色选择职业和构建的东西。我可以让它选择类(class),但我不明白为什么它不选择构建。我还是个新手,所以这可能不是最干净或最简单的方法。

import random

Classes=["Demon Hunter","Monk","Crusader","Barbarian","Necromancer","Wizard","Witch Doctor"]

DHBuild=["Impale","Multishot","Natalya's"]
MBuild=["Wave of Light","Uliana's EP","Sunwuko LTK",]
CBuild=["Condemn","Blessed Shield","Sweep Attack"]
BRBuild=["Hammer of the Ancients","WhirlWind","LeapQuake"]
NECROBuild=["Pestilance","Rathma Mages","Inarius"]
WIZBuild=["Frozen Orb","Lightning Hydra","TalVyrs Archon"]
WDBuild=["Arachyr FireBats","Jade Harvester","Helltooth FireBats"]

picked=print(random.choice(Classes))

print(picked)

if picked=="Demon Hunter":
PickedBuild=print(random.choice(DHBuild))
print(PickedBuild)

if picked=="Monk":
PickedBuild=print(random.choice(MBuild))
print(PickedBuild)

if picked=="Crusader":
PickedBuild=print(random.choice(CBuild))
print(PickedBuild)

if picked=="Barbarian":
PickedBuild=print(random.choice(BRBuild))
print(PickedBuild)

if picked=="Necromancer":
PickedBuild=print(random.choice(NECROBuild))
print(PickedBuild)

if picked=="Wizard":
PickedBuild=print(random.choice(WIZBuild))
print(PickedBuild)

if picked=="Witch Doctor":
PickedBuild=print(random.choice(WDBuild))
print(PickedBuild)

input("press something to close")

最佳答案

问题在于您试图将打印的返回设置为变量,但您无法这样做

picked=print(random.choice(Classes))

因为它给出了SyntaxError:无效语法

这就是您想要做的:

picked = random.choice(Classes)
print(picked)

下面的代码现在应该可以工作了

import random

Classes=["Demon Hunter","Monk","Crusader","Barbarian","Necromancer","Wizard","Witch Doctor"]

DHBuild=["Impale","Multishot","Natalya's"]
MBuild=["Wave of Light","Uliana's EP","Sunwuko LTK",]
CBuild=["Condemn","Blessed Shield","Sweep Attack"]
BRBuild=["Hammer of the Ancients","WhirlWind","LeapQuake"]
NECROBuild=["Pestilance","Rathma Mages","Inarius"]
WIZBuild=["Frozen Orb","Lightning Hydra","TalVyrs Archon"]
WDBuild=["Arachyr FireBats","Jade Harvester","Helltooth FireBats"]

picked= random.choice(Classes)

print(picked)

if picked=="Demon Hunter":
PickedBuild = random.choice(DHBuild)
print(PickedBuild)

if picked=="Monk":
PickedBuild= random.choice(MBuild)
print(PickedBuild)

if picked=="Crusader":
PickedBuild= random.choice(CBuild)
print(PickedBuild)

if picked=="Barbarian":
PickedBuild= random.choice(BRBuild)
print(PickedBuild)

if picked=="Necromancer":
PickedBuild= random.choice(NECROBuild)
print(PickedBuild)

if picked=="Wizard":
PickedBuild= random.choice(WIZBuild)
print(PickedBuild)

if picked=="Witch Doctor":
PickedBuild= random.choice(WDBuild)
print(PickedBuild)

input("press something to close")

关于python - 根据其他列表从列表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52954077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com