请用Python写3个类:人,狗,武器。人包括姓名,年龄,性别,并使用武器,人的血值是100; 狗包括姓名,年龄,攻击值,狗的血值是100; 武器类,包括3类武器及杀伤力棍30,刀40,枪45;
时间: 2023-05-20 10:07:00 浏览: 93
好的,以下是我为您编写的Python代码:
class Person:
def __init__(self, name, age, gender, weapon):
self.name = name
self.age = age
self.gender = gender
self.weapon = weapon
self.health = 100
class Dog:
def __init__(self, name, age, attack):
self.name = name
self.age = age
self.attack = attack
self.health = 100
class Weapon:
def __init__(self, name, damage):
self.name = name
self.damage = damage
gun = Weapon("枪", 45)
knife = Weapon("刀", 40)
stick = Weapon("棍", 30)
请注意,这只是一个简单的示例,您可以根据您的需求进行修改和扩展。
阅读全文