我一直在關注this系列YouTube視頻,以獲得更多的Python方法。我對代碼的某些功能沒有深入的瞭解,但是我或多或少地得到了每件作品應該實現的功能,儘管我可能不知道如何實現。Python代碼在「if self.hp <0」行上返回語法錯誤
我得到的最後一行這裏語法錯誤:
class Character(object):
def __init__(self, name, hp):
self.name = name
self.hp = hp
self.dead = False
def attack(self, other):
pass
def update(self):
if self.hp < 0 #Error's on this line
self.dead = True
self.hp = 0
這裏是回溯:
Traceback (most recent call last): File "game.py", line 4, in
<module>
from Characters.player import * File "/Users/Devlin/Desktop/Dev/Python/rpg/Characters/player.py", line 2,
in <module>
from character import * File "/Users/Devlin/Desktop/Dev/Python/rpg/Characters/character.py", line
12
if self.hp < 0
^SyntaxError: invalid syntax
添加':',如果self.hp <0:' –