我正在尝试制作一种可以为游戏中的下一个角色选择课程和构造的东西。我可以选择它,但是我不知道为什么它不能选择构建。我仍然很新,所以这可能不是最干净或最简单的方法。
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")
答案 0 :(得分:0)
问题是您试图将打印的返回值设置为变量,而这是您不能做到的
picked=print(random.choice(Classes))
因为它给出了SyntaxError: invalid syntax
这就是您想要做的:
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")