samedi 13 mars 2021

I get an invalid syntax error at every if, elif and else line, specifically at ":"

I get a syntax error at the second if (if playerroll > enemyroll:) and at the subsequent elif and else, al pointed at the ":". I really don't know how to resolve this. I'm a total beginner

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

Aucun commentaire:

Enregistrer un commentaire