python生成一个带名字的爱心
时间: 2023-07-04 14:20:12 浏览: 162
好的,以下是生成带名字的爱心的 Python 代码:
```python
your_name = input("请输入你的名字:")
heart = '''
******** ********
** ** ** **
** ** **
** **
** **
** **
** **
** **
** **
** **
** **
**
'''
heart = heart.replace('*', '♥')
name_heart = ""
for line in heart.split('\n'):
if line.strip() != '':
name_heart += line.center(len(line) + len(your_name)).replace(your_name.center(len(your_name) * 2), your_name) + '\n'
print(name_heart)
```
运行代码后,程序会要求你输入你的名字,并在屏幕上生成一个带你名字的爱心。