圣诞期间,看了下python的for循环。刚好实践一下,一时兴起,就写了个圣诞树的小程序。供诸君一乐!
下面附上代码:
#coding:utf-8 import sys def christmas(h): print ‘\033[1;36;40m\t欢迎光临!\n正在为你制作专属于您的圣诞树,请稍等!\033[0m‘ print ‘\033[1;32;40m‘ # print ‘\t‘, for i in range(1,h+1): print ‘\t‘, for j in range(0,h-i): print ‘ ‘, i=2*i-1 for j in range(0,i): print ‘*‘, print for i in range(1,h+1): print ‘\t‘, for j in range(1,h): print ‘ ‘, print ‘*‘ print ‘\033[1;31;40m Merry Christmas!\033[0m‘ christmas(int(sys.argv[1]))
下边是运行结果:
时间: 2024-10-14 06:03:23