编程语言
首页 > 编程语言> > python打印心形文字

python打印心形文字

作者:互联网

import time
sentence = "Dear, I love you forever!"    ## 将该字符串以心形文字打印出来
for char in sentence.split():
   allChar = []
   for y in range(12, -12, -1):
       lst = []
       lst_con = ''
       for x in range(-30, 30):
            formula = ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3
            if formula <= 0:
                lst_con += char[(x) % len(char)]
            else:
                lst_con += ' '
       lst.append(lst_con)
       allChar += lst
   print('\n'.join(allChar))
   time.sleep(1)

运行示例如下:

标签:12,sentence,python,心形,打印,0.05,0.1,lst,formula
来源: https://blog.csdn.net/weixin_43821854/article/details/93882414