行测 中国移动 windows mvvm configuration coldfusion LimeJS 百度seo关键词优化 纯html网页模板 oracle连接字符串 bootstrap文本框 查看nodejs版本 python相对路径怎么写 表白网页源码 python中的index python字符串匹配 python读取mysql数据 python循环10次 java正则匹配 java的接口 java编译 配置java开发环境 javaworld java数组输出 java安装 linuxtail命令 tftpd64 图片生成网址 win10有哪些版本 什么是人肉搜索 黑域怎么用 快递电子面单打印软件 mysql数据库恢复 微信群群发软件 刷新当前页面 lol游戏环境异常 dbgview mysql嵌套查询 pathping urlpattern
当前位置: 首页 > 学习教程  > python

python新年祝福代码_python 新年祝福

2021/2/6 22:25:13 文章标签: 测试文章如有侵权请发送至邮箱809451989@qq.com投诉后文章立即删除

import osimport timeimport randomimport pygameimport colorama‘‘‘一些变量‘‘‘BGMPATH ‘bgm.mp3‘colorama.init(convertTrue)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 …

import os

import time

import random

import pygame

import colorama

‘‘‘一些变量‘‘‘

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

‘‘‘程序背景音乐‘‘‘

# def playBGM(bgm_path):

# pygame.mixer.init()

# pygame.mixer.music.load(bgm_path)

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

‘‘‘换行‘‘‘

def nextLine():

time.sleep(0.3)

print()

‘‘‘画心‘‘‘

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

‘‘‘显示祝福文字‘‘‘

def showText():

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

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

‘‘‘画花‘‘‘

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

‘‘‘清屏‘‘‘

def clearScreen():

try:

os.system(‘cls‘)

except:

os.system(‘clear‘)

‘‘‘主程序‘‘‘

def main():

# playBGM(BGMPATH)

clearScreen()

while True:

drawHeart()

nextLine()

showText()

nextLine()

nextLine()

drawFlower()

print()

if __name__ == ‘__main__‘:

main()

原文:https://www.cnblogs.com/walkwaters/p/12128016.html

相关资源:新年快乐! python实现绚烂的烟花绽放效果

本文链接: http://www.dtmao.cc/news_show_2000084.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?