今天是母亲节,孩子们自然要送上母亲的节日祝福。如果和妈妈在一起,可以直接说几句祝福的话,送一些小礼物。是的,如果你不在你妈妈身边,你可以打电话问好。当然,作为程序员,除了以上的祝福方式,我们还可以编写一个小程序,为妈妈送上特别的节日祝福。在这篇文章中,我们用Python为妈妈做一个特别的节日祝福。代码实现如下:colorama.init(convert=True)RED=colorama.Fore.RED+colorama.Style.BRIGHTCYAN=colorama.Fore.CYAN+colorama.Style.BRIGHTGREEN=colorama.Fore.GREEN+colorama.Style.BRIGHTYELLOW=colorama.Fore.YELLOW+colorama.Style.BRIGHTMAGENTA=colorama.Fore.MAGENTA+colorama.Style.BRIGHT#printheaderforiinrange(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\]#Rose的空列位置flowerBreakLines=\[7,15,23,31,39,46\]#添加空列defaddSpaces(a):count=awhilecount>0:print('',end='')count-=1#添加一个空行defnewLineWithSleep():time.sleep(0.3)print('\\n',end='')play=0whileplay==0:Left\_Spaces=randint(8,80)addSpaces(Left\_Spaces)#drawheartforiinrange(0,78):ifiinheartBreakLines:newLineWithSleep()addSpaces(Left\_Spaces)elifiinheartStars:print(RED+'\*',end='')elifiin(32,36):打印(GREEN+'M',end='')elifi==34:print(GREEN+'O',end='')else:print('',end='')newLineWithSleep()addSpaces(randint(8,80))print(CYAN+"HapyMothr'sDay!",end='')newLineWithSleep()newLineWithSleep()Left\_Spaces=randint(8,80)addSpaces(Left\_Spaces)#画花foriinrange(0,47):ifi在flowerBreakLines:newLineWithSleep()addSpaces(Left\_Spaces)elifiin(2,8,12,18):打印(MAGENTA+'{',end='')elifiin(3,1,1):打印(MAGENTA+'\_',end='')elifiin(4,10,14,20):打印(MAGENTA+'}',end='')elifiin(27,35,43):打印(GREEN+'|',end='')elifiin(34,44):打印(GREEN+'~',end='')elifi==11:打印(YELLOW+,结束='')else:print('',end='')print('\\n',end='')查看效果:源码在公众号Python小二后台回复200510获取
