Python Code saying it is None, but it isn't

Question:
I am currently trying to implement an XP system. There has to be a round_max for that to work. I define it as 3, but when I check if it’s None or not, it returns True.

CODE:

def full_battle_over_check(enemy_list, heros, round=None, round_max = None):
    t = []
    for li in enemy_list:
        if all(enemy.permissions == "dead" for enemy in enemy_list):
            t.append(True)
        else:
            t.append(False)
    if round is None:
        if all(t):
            print("You won!")
            wait(1)
            for hero in heros:
                hero.exp += 100
                print(f"{hero.name} got 100 exp!")
                wait(0.5)
                while True:
                    if hero.exp >= hero.limit:
                        hero.level += 1
                        hero.exp -= hero.limit
                        hero.limit = round(hero.limit * 1.75)
                        wait(0.5)
                        print(f"{hero.name} leveled up to level {hero.level}! {hero.exp} left!")
                    else:
                        break
        else:
            print("You lose.")
    else:
        if round_max is None:
            print("ERROR: ROUND MAX NOT DEFINED")
            return
        if all(t):
            print(f"You won round {round}!")
            wait(0.5)
            if round < 3:
                print(f"{3 - round} round(s) left.")
            elif round <= 0 or round >= 4:
                raise InvalidInputError("Round Number Invalid")
            else:
                print("You Win!")
        else:
            print("You lose.")

Where do you set it to three? Can you send a link to the Repl?

I wasn’t doing it on replit Here’s the link: https://replit.com/@RandomDreamWalker2011/WIP-LOR?v=1

1 Like

You’re calling sing_round_battle(h, e) as the first function call in the battle.py file. That function creates an instance of the Battle class without providing a value to round_max: battle = Battle(heros, enemies)

3 Likes

I did that but when I checked it after it ran on Replit Pycharm , allof them still only have 0 exp.

Hi @RandomDreamWalker201 I ran through the game and got this message after all enemies died:

image

It sounds like @rytrujillo might be correct. Have you investigated this already?

Oops, I forgot to update it on replit. It should give this error now:

  File "main.py", line 5, in <module>
    import battle
  File "/home/runner/WIP-LOR/battle.py", line 296, in <module>
    standard_battle(h, e1, e2, e3)
  File "/home/runner/WIP-LOR/battle.py", line 280, in standard_battle
    battle.battle()
  File "/home/runner/WIP-LOR/battle.py", line 264, in battle
    self.round += full_battle_over_check(self.enemies, self.watchers, self.round, self.round_max)
  File "/home/runner/WIP-LOR/battle.py", line 99, in full_battle_over_check
    hero.limit = round(hero.limit * 1.75)
TypeError: 'int' object is not callable

I am not calling hero.limit though.

Not sure if you’ve found the issue yet, but the problem is not that you’re calling hero.limit. The problem is that you’re calling round. Your local int variable named “round” is shadowing the built-in Python function round(). You need to change the name of your local variable. PyCharm will usually tell you about this kind of issue.

2 Likes