python写圣诞祝福_圣诞节啊,用Python写一棵圣诞树出来

实图:

178793332_1_2019122511085150

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

178793332_2_20191225110851238

178793332_3_20191225110851425

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

所以一共是两个文件:

178793332_4_20191225110851816

环境参数:

Python == 3.6.1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值