mardi 9 novembre 2021

My elif doesn't work for some reason? (Python) [closed]

so i am making a python turn based combat system and cant understand why one of the "elif"s don't work. i thought at first it was because i had a nested if before it but after i fixed it it turned out that wasn't the case Heres the code segment

import time
import random

name = "Player"
maxhp = 100
hitpoints = 100
defense = 0
attack = 3

enemy = "Red slime"
enemy_hitpoints = 35
enemy_defense = 1
enemy_attack = 5
enemy_charged = 0

while enemy_hitpoints >= 0:
  
  if enemy_charged == 1 and block == 0:
    current_attack = round(enemy_attack * random.uniform(0.9, 1.3) * 2.5) - defense
    hitpoints -= current_attack
    print("The %s struck a powerful blow and dealt %d damage to you." % (enemy, current_attack))

  elif enemy_charged == 1 and block == 1:
    hitpoints -= round(current_attack / 4)
    enemy_hitpoints-= round(current_attack / 2)
    print("The %s tried to attack you but you blocked it, dealing %d damage to you and %d damage to itself." % (enemy, round(current_attack / 4), round(current_attack / 2))
  
  #Why does this give me a syntax error \/
  elif random.randint(1, 4) == 1:
    enemy_charged = 1
    print("The %s is charging up a powerful attack" % (enemy))

  else:
    current_attack = round(enemy_attack * random.uniform(0.9, 1.3)) - defense
    hitpoints -= current_attack
    print("The %s dealt %d damage to you." % (enemy, current_attack))

why does it tell me that my elif is a syntax error

    elif random.randint(1, 4):
    ^
SyntaxError: invalid syntax

could you explain in a simple way with a small example because i'm quite new to code

Aucun commentaire:

Enregistrer un commentaire