帕恰狗python代码
时间: 2023-11-09 07:00:51 浏览: 244
帕恰狗.py..py
以下是帕恰狗的 Python 代码:
```python
import random
class PachaDog:
def __init__(self, name):
self.name = name
self.tricks = []
def teach_trick(self, trick):
self.tricks.append(trick)
def do_trick(self):
if self.tricks:
trick = random.choice(self.tricks)
print(f"{self.name} does a {trick}!")
else:
print(f"{self.name} doesn't know any tricks yet.")
pacha = PachaDog("Pacha")
pacha.teach_trick("sit")
pacha.teach_trick("roll over")
pacha.teach_trick("play dead")
pacha.do_trick()
pacha.do_trick()
pacha.do_trick()
```
输出:
```
Pacha does a sit!
Pacha does a play dead!
Pacha does a roll over!
```
阅读全文