if语句上方缺少
我在第二个if(如果playerroll>enemyroll:(和随后的elif和else处得到语法错误,al指向":&";。我真的不知道该怎么解决。我完全是的初学者
import random
playerpf=10
goblinpf=1
print("You advance in the dark cave" )
print("A nasty goblin ambush you! You have to defend yourself!" )
goblinfight= input("Fight(1) or flee(2)?" )
if goblinfight==str(1):
while goblinpf>0:
enemyroll=int(random.choice(d6))
playerroll=int(random.choice(d10))
print("The enemy rolls a " +str(enemyroll))
print("You roll a "+str(playerroll)
if (playerroll > enemyroll):
print("You kill the goblin!")
goblinpf=goblinpf-1
elif playerroll==enemyroll:
print ("Your sword clashes with your foe's weapon!")
else:
playerpf=playerpf-1
print("The goblin hits you and you lose 1 pf!")
print("You now have " +str(playerpf)+ "pf")
else:
print("As you run away from the goblin, you hear his laugh echoing in the cavern")
右括号。
print("You roll a "+ str(playerroll))
您在第13行末尾遗漏了一个右括号。
更换
print("You roll a "+str(playerroll)
带有
print("You roll a "+str(playerroll))
完整的运行代码