python迪迦奥特曼代码
时间: 2023-11-12 10:59:04 浏览: 231
好的,以下是一个简单的 Python 迪加奥特曼代码:
```python
class Ultraman:
def __init__(self, name, energy, attack):
self.name = name
self.energy = energy
self.attack = attack
def fight(self, monster):
if self.energy <= 0:
print(f"{self.name}能量不足,无法战斗!")
return
print(f"{self.name}发起了攻击!")
monster.energy -= self.attack
if monster.energy <= 0:
print(f"{monster.name}被打败了!")
else:
print(f"{monster.name}还剩下{monster.energy}点能量。")
class Monster:
def __init__(self, name, energy, attack):
self.name = name
self.energy = energy
self.attack = attack
ultraman = Ultraman("迪加奥特曼", 100, 20)
monster = Monster("怪兽", 80, 15)
ultraman.fight(monster)
```
阅读全文