用python输出原神元素类
时间: 2023-06-16 16:02:41 浏览: 45
可以使用以下代码来定义原神中的元素类:
```python
class Element:
def __init__(self, name, color):
self.name = name
self.color = color
def __str__(self):
return self.name
class Pyro(Element):
def __init__(self):
super().__init__("Pyro", "red")
class Hydro(Element):
def __init__(self):
super().__init__("Hydro", "blue")
class Anemo(Element):
def __init__(self):
super().__init__("Anemo", "green")
class Electro(Element):
def __init__(self):
super().__init__("Electro", "purple")
class Cryo(Element):
def __init__(self):
super().__init__("Cryo", "white")
class Geo(Element):
def __init__(self):
super().__init__("Geo", "yellow")
class Dendro(Element):
def __init__(self):
super().__init__("Dendro", "green")
```
这里我们定义了一个基类 `Element`,然后创建了每个元素的子类,例如火元素 Pyro、水元素 Hydro 等等。每个子类都继承了基类 `Element`,并在 `__init__` 方法中初始化了元素名字和颜色。我们还可以使用 `__str__` 方法来打印元素的名字。