跳动的爱心Python代码
时间: 2023-07-23 20:08:44 浏览: 107
以下是跳动的爱心Python代码:
```
import time
def heart_animation():
heart = '\033[91m' + " ♥♥ " + '\033[0m'
empty_heart = " "
heart_list = [empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, heart, heart, empty_heart]
while True:
for i in range(9):
time.sleep(0.1)
print(heart_list[i])
heart_list.insert(0, heart_list.pop())
if i == 8:
heart_list = [empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, heart, heart, empty_heart]
heart_animation()
```
运行代码会输出一个跳动的爱心动画。
相关问题
紫色跳动爱心python代码
以下是一个使用Python编写的紫色跳动爱心代码:
```python
import time
while True:
for i in range(6):
print('\033[95m' + u'\u2665' + '\033[0m', end='')
time.sleep(0.5)
for i in range(6):
print('\033[91m' + u'\u2665' + '\033[0m', end='')
time.sleep(0.5)
print()
```
跳动的爱心python代码
以下是跳动的爱心Python代码:
```
import time
def heart_animation():
heart = '\033[91m' + " ♥♥ " + '\033[0m'
empty_heart = " "
heart_list = [empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, heart, heart, empty_heart]
while True:
for i in range(9):
time.sleep(0.1)
print(heart_list[i])
heart_list.insert(0, heart_list.pop())
if i == 8:
heart_list = [empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, heart, heart, empty_heart]
heart_animation()
```
运行代码会输出一个跳动的爱心动画。
阅读全文