今天是母親節,作兒女的天然要爲母親送上節日的祝福,若是本身在母親身邊的話,能夠直接說幾句祝福的話以及送一些小禮物什麼的,要是不在母親身邊的話,能夠打個電話問候一下。python
固然了,做爲一個程序員,除了上面的祝福方式,咱們還能夠編寫一個小程序爲母親送上特殊的節日祝福,本文咱們使用 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='')
看一下效果:
源碼在公衆號 Python小二 後臺回覆 200510 獲取。spa