用 Python 送上特殊的母亲节祝福
发布日期:2021-06-30 11:42:40
浏览次数:2
分类:技术文章
本文共 2156 字,大约阅读时间需要 7 分钟。
今天是母亲节,做儿女的自然要为母亲送上节日的祝福,如果自己在母亲身边的话,可以直接说几句祝福的话以及送一些小礼物什么的,要是不在母亲身边的话,可以打个电话问候一下。当然了,作为一个程序员,除了上面的祝福方式,我们还可以编写一个小程序为母亲送上特殊的节日祝福,本文我们使用 Python 来为自己的母亲制作一个特殊的节日祝福。
代码实现如下所示:
colorama.init(convert=True) RED = colorama.Fore.RED + colorama.Style.BRIGHT CYAN = colorama.Fore.CYAN + colorama.Style.BRIGHT GREEN = colorama.Fore.GREEN + colorama.Style.BRIGHT YELLOW = colorama.Fore.YELLOW + colorama.Style.BRIGHT MAGENTA = colorama.Fore.MAGENTA + colorama.Style.BRIGHT # 打印抬头 for i in range(1, 35): print('') # \*的位置 heartStars = \[2, 4, 8, 10, 14, 20, 26, 28, 40, 44, 52, 60, 64, 76\] # 空格的位置 heartBreakLines = \[13, 27, 41, 55, 69, 77\] # 玫瑰的空列位置 flowerBreakLines = \[7, 15, 23, 31, 39, 46\] # 添加空列 def addSpaces(a): count = a while count > 0: print(' ', end='') count -= 1 # 添加空行 def newLineWithSleep(): time.sleep(0.3) print('\\n', end='') play = 0 while play == 0: Left\_Spaces = randint(8, 80) addSpaces(Left\_Spaces) # 画心 for i in range(0, 78): if i in heartBreakLines: newLineWithSleep() addSpaces(Left\_Spaces) elif i in heartStars: print(RED + '\*', end='') elif i in (32, 36): print(GREEN + 'M', end='') elif i == 34: print(GREEN + 'O', end='') else: print(' ', end='') newLineWithSleep() addSpaces(randint(8, 80)) print(CYAN + "H a p p y M o t h e r ' s D a y !", end='') newLineWithSleep() newLineWithSleep() Left\_Spaces = randint(8, 80) addSpaces(Left\_Spaces) # 画花 for i in range(0, 47): if i in flowerBreakLines: newLineWithSleep() addSpaces(Left\_Spaces) elif i in (2, 8, 12, 18): print(MAGENTA + '{', end='') elif i in (3, 9, 13, 19): print(MAGENTA + '\_', end='') elif i in (4, 10, 14, 20): print(MAGENTA + '}', end='') elif i in (27, 35, 43): print(GREEN + '|', end='') elif i in (34, 44): print(GREEN + '~', end='') elif i == 11: print(YELLOW + 'o', end='') else: print(' ', end='') print('\\n', end='')
看一下效果:
转载地址:https://ityard.blog.csdn.net/article/details/106032858 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年05月01日 08时58分06秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Android设置字体颜色
2019-04-30
libBasicUsageEnvironment.so.0: cannot restore segment prot after reloc: Permission denied
2019-04-30
dynamic_cast
2019-04-30
如何将QT应用程序打包发布
2019-04-30
Qt远程连接MySql数据库
2019-04-30
Windows下Qt的MYSQL数据库开发步骤
2019-04-30
QtCreator中常用快捷键总结
2019-04-30
ReferenceError: Unknown plugin component
2019-04-30
vue 引入 element-ui 报 es2015 的错
2019-04-30
图片暴力压缩
2019-04-30
vue 插件 之 生成二维码 qrcodejs2
2019-04-30
javascript 之 获取毫秒时间戳
2019-04-30
python 环境搭建无坑
2019-04-30
python 配置web自动化测试框架 selenium
2019-04-30
python 自动化测试 selenium 框架 - 1
2019-04-30
html 导出 excel -- 1
2019-04-30
html 导出 excel 设置单元格文本格式 -- 2
2019-04-30
html 导出 excel 单元格合并 --3
2019-04-30
javascript 时间格式在iphone上的兼容问题 亲测有用 无坑点
2019-04-30