您现在的位置是:首页 > 文章详情

圣诞节啊,用Python写一棵圣诞树出来

日期:2019-12-24点击:733

实图:

screenshot

效果如图:哈哈哈哈哈。。。

screenshot

screenshot

Python源代码:

from random import randint from time import sleepimport coloramafrom colorama import Fore, Back, Stylecolorama.init()rnd2 = randint(1,60)def gentree():for x in range(1,30,2):rnd1 = randint(1,rnd2)if x == 1:ch = "$"elif rnd1 % 4 == 0:ch = "o"elif rnd1 % 3 == 0:ch = "j"elif rnd1 % 5 == 0:ch = "o"elif rnd1 % 7 == 0:ch = "j"else:ch ="*"if ch == "$":print(Fore.RED +"{:^33}".format(ch x))elif ch == "o":print(Fore.RED +"{:^33}".format(ch x))elif ch == "j":print(Fore.YELLOW +"{:^33}".format(ch x))else:print(Fore.GREEN +"{:^33}".format(ch x))print("{:^33}".format('|||'))print("{:^33}".format('|||')) print("{:^33}".format(' Merry_christmas '))sleep(.24)gentree()
我试了一下,用IDLE运行这段代码效果不咋滴。为了让圣诞树一直在闪,我决定用批处理的方式,写一个bat脚本来运行py文件。

bat代码:

@echo offD:cd D:Tree:start python Tree.pygoto start
所以一共是两个文件:

圣诞节啊,用Python写一棵圣诞树出来
环境参数:
screenshot

原文链接:https://yq.aliyun.com/articles/740564
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章