我正在尝试通过制作选课程序来练习 OOP
# let's make a character selection program
class player:
def __init__(self, username, age, weight, height, gender):
self.username = username
self.age = age
self.weight = weight
self.height = height
self.gender = gender
class soldier(player):
strength = weight*height*2
print strength
print "Please enter the following"
player_username = raw_input("Please enter a username: ")
player_age = input("Please enter your age: ")
player_weight = input("Please enter your weight: ")
player_height = input("Please enter your height: ")
player_gender = raw_input("Please enter your gender: ")
player_character_class = raw_input("Please enter a player class: ")
character_obj = player(player_username, player_age, player_weight, player_height, player_gender)
print soldier.strength
但是,我得到了错误
Traceback (most recent call last):
File "character_select.py", line 11, in <module>
class soldier(player):
File "character_select.py", line 12, in soldier
strength = weight*height*2
NameError: name 'weight' is not defined
不太确定如何定义重量。我以为我通过将“玩家”传递给“焊料”来继承它。有人可以帮我吗?
谢谢!