Happy New Year code written in python, python holiday blessing source code

This article mainly introduces the Happy New Year code written in python. It has certain reference value and friends in need can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to understand it together.

import us

import time

import random

import pygame

import colorama

'''Some variables'''

BGMPATH = ‘bgm.mp3‘

colorama.init(convert=True)

STARS = [2, 4, 8, 10, 14, 20, 26, 28, 40, 44, 52, 60, 64, 76]

HEARTS = [13, 27, 41, 55, 69, 77]

FLOWERS = [7, 15, 23, 31, 39, 46]

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

'''Program background music'''

# def playBGM(bgm_path):

# pygame.mixer.init()

# pygame.mixer.music.load(bgm_path)

# pygame.mixer.music.play(-1)

'''Newline'''

def nextLine():

time.sleep(0.3)

print()

'''Drawing Heart'''

def drawHeart():

num_spaces = random.randint(8, 80)

print(‘ ‘ * num_spaces, end=‘‘)

for i in range(78):

if i in HEARTS:

nextLine()

print(‘ ‘ * num_spaces, end=‘‘)

elif i in STARS:

print(RED + ‘*‘, end=‘‘)

elif i in [31, 35]:

print(GREEN + ‘2‘, end=‘‘)

elif i in [33, 37]:

print(GREEN + ‘0‘, end=‘‘)

else:

print(‘ ‘, end=‘‘)

'''Show blessing text'''

def showText():

print(‘ ‘ * random.randint(8, 80), end=‘‘)

print(CYAN + "Happy new year!", end=‘‘)

'''Draw flowers'''

def drawFlower():

num_spaces = random.randint(8, 80)

print(‘ ‘ * num_spaces, end=‘‘)

for i in range(47):

if i in FLOWERS:

nextLine()

print(‘ ‘ * num_spaces, end=‘‘)

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=‘‘)

'''Clear screen'''

def clearScreen():

try:

os.system(‘cls‘)

except:

os.system(‘clear‘)

'''Main program'''

def main():

# playBGM(BGMPATH)

clearScreen()

while True:

drawHeart()

nextLine()

showText()

nextLine()

nextLine()

drawFlower()

print()

if __name__ == ‘__main__‘:

main()

Original text: https://www.cnblogs.com/walkwaters/p/12128016.html

Supongo que te gusta

Origin blog.csdn.net/mynote/article/details/135050610
Recomendado
Clasificación