想必各位程序员朋友在面临情人节,520等诸多节日时,总会出现选择困难症的情况,在这里小编整理了一段非常简单且实用的简单Python爱心代码,希望能帮助到各位。如有需要更好看,更动态的爱心,请点赞收藏一波,小编会持续更新的。
import time
def print_love_heart():
heart = [" ** ** ", " **** **** ", "***********", " ********* ", " ******* ", " ***** ",
" *** ", " * "]
for i in range(len(heart)):
print(heart[i])
print("\nH", end="")
time.sleep(0.2)
print("e", end="")
time.sleep(0.2)
print("l", end="")
time.sleep(0.2)
print("l", end="")
time.sleep(0.2)
print("o", end="")
time.sleep(0.2)
print(" ", end="")
time.sleep(0.2)
print("W", end="")
time.sleep(0.2)
print("o", end="")
time.sleep(0.2)
print("r", end="")
time.sleep(0.2)
print("l", end="")
time.sleep(0.2)
print("d", end="")
time.sleep(0.2)
print_love_heart()
运行结果如下:
注意,使用pyhon实现的功能比较复杂并且代码比较多的情况下,建议使用.py文件来存储代码,并在pyhon的开发环境中运行该python文件。如有其他疑问,欢迎在评论区留言。