数字人python代码
时间: 2023-08-12 09:08:00 浏览: 356
以下是一个简单的数字人 Python 代码示例:
```python
import random
class DigitalPerson:
def __init__(self, name, age, interests, occupation):
self.name = name
self.age = age
self.interests = interests
self.occupation = occupation
def introduce(self):
print("Hi, my name is " + self.name + ". I am " + str(self.age) + " years old.")
print("My interests include: ")
for interest in self.interests:
print("- " + interest)
print("I work as a " + self.occupation + ".")
def greet(self):
greetings = ["Hello!", "Hi there!", "Nice to meet you!"]
print(random.choice(greetings))
```
可以按照以下方式使用该类:
```python
person1 = DigitalPerson("Alice", 25, ["reading", "running"], "software engineer")
person1.introduce() # 输出数字人 Alice 的自我介绍
person1.greet() # 输出数字人 Alice 的问候语
person2 = DigitalPerson("Bob", 30, ["painting", "hiking"], "teacher")
person2.introduce() # 输出数字人 Bob 的自我介绍
person2.greet() # 输出数字人 Bob 的问候语
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)