首先先放出我的第一个使用Pygame写的程序“菜虚鲲大战蔡徐坤”。

import random
import pygame
import sys
import time
pygame.init()#初始化
#主窗口
screen_image = pygame.display.set_mode((800,600))#设置分辨率
screen_rect = screen_image.get_rect()#标题栏
pygame.display.set_caption('人工智能2x0xXXX2021xxxxxx')#设置文件名#飞船
ship_image = pygame.image.load('image/cai1.bmp')
ship_rect = ship_image.get_rect()
ship_rect.center = screen_rect.center#居中对齐#子弹1
bullet_rect = pygame.Rect(0,0,3,15)
bullet_rect.midbottom = ship_rect.midtop
bullet_rect.x=0
bullet_rect.y=0#散弹枪
grape_rect = pygame.Rect(0,0,3,15)
grape_rect.midbottom=ship_rect.midtop
grape_rect.x=bullet_rect.x+5
grape_rect.x=0
grape_rect.y=0#怪物monster_image = pygame.image.load('image/cai2.bmp')
monster_rect = ship_image.get_rect()
monster_rect.x = 360#文字
txt_font = pygame.font.SysFont(None,48)
txt_image = txt_font.render('caixukun',True,(60,60,60),(255,0,0))
txt_rect = txt_image.get_rect()while True:for event in pygame.event.get():if event.type==pygame.QUIT:sys.exit()elif event.type==pygame.KEYDOWN:if event.key == pygame.K_LEFT or event.key == pygame.K_a:ship_rect.x-=20if event.key == pygame.K_RIGHT or event.key == pygame.K_d:ship_rect.x+=20if event.key == pygame.K_UP or event.key == pygame.K_w:ship_rect.y-=20if event.key == pygame.K_DOWN or event.key == pygame.K_s:ship_rect.y+=20if event.key == pygame.K_j:bullet_rect.midbottom = ship_rect.midtopif event.key == pygame.K_k:#bullet_rect.midbottom = ship_rect.midtopgrape_rect.midbottom = ship_rect.midtopgrape_rect.x+=10# if monster_rect.x == bullet_rect.x or monster_rect.y == bullet_rect.y:#     monster_rect.y = 0#     monster_rect.x +=10#     pass# if monster_rect.y-bullet_rect.y<=10:#     if bullet_rect.x <= monster_rect.x:#         monster_rect.x+=1#         pass#     elif bullet_rect.x > monster_rect.x:#         monster_rect.x-=1#     passif abs(monster_rect.x-bullet_rect.x)<=100 and abs(monster_rect.y-bullet_rect.y)<=100:bullet_rect.y = 0monster_rect.y=0monster_rect.x = random.randint(0,600)passmonster_rect.y+=1bullet_rect.y-=20grape_rect.y-=1time.sleep(0.05)#绘制图像screen_image.fill((0,128,128))#设置背景颜色screen_image.blit(ship_image,ship_rect)#设置飞船screen_image.blit(monster_image,monster_rect)pygame.draw.rect(screen_image,(60,60,60),bullet_rect)pygame.draw.rect(screen_image,(80,80,80),grape_rect)screen_image.blit(txt_image,txt_rect)pygame.display.flip()#刷新

我在学习python的时候,学习的方向以及顺序都跟去年学习C++差不多,大致就是先从输入输出开始,然后是基本的语句,字典、列表、元组等等,然后是文件输入输出以及类与对象、继承多态等等。

这其中有很多知识我都是早早学完了,python我在去年就把基础的知识学的差不多了,Scott自学python——字符串学习笔记_轩Scott的博客-CSDN博客

Scott自学python——字典学习笔记_轩Scott的博客-CSDN博客

Scott自学python——元组学习笔记_轩Scott的博客-CSDN博客

Scott自学python——列表学习笔记_轩Scott的博客-CSDN博客

这些都是我以前学习python的博客笔记。

暑假期间我主要是学习了pygame和python的文件输入输出以及类与对象、继承多态等等,以下是我在练习中写的核酸检测登记系统

import datetime
import csv
class Nuclear_Test():#核酸检测结果def __init__(self,id):self.time = datetime.datetime.now()self.result = Falseself.id = idpassdef Output(self):print('Nuclear test time is',self.time,',result=',self.result)passclass Person():#核酸检测人员信息def __init__(self,name,id):self.name = name#名self.id = id#身份证号self.Nuclear = []#self.Nuclear_Number = 0#次数passdef Add_Nuclear_Test(self,result = False):#index = Nuclear_Test(self.id)index.result=resultself.Nuclear.append(index)self.Nuclear_Number+=1passdef Output(self):print('Chinaman name',self.name.title(),'Chinaman id',self.id)for i in range(self.Nuclear_Number):self.Nuclear[i].Output()passpasspass
class System():def __init__(self):print('Initializing the system.')self.Person_Data = []self.number=int(0)passdef Add_Data(self,data):self.Person_Data.append(data)self.number+=1passdef Find_Data(self,id):index = Falsefor i in range(self.number):if self.Person_Data[i].id == id:print('Found the monster data.',end=' ')self.Person_Data[i].Output()index = Truepasspassif index == False:print('The Chinaman data was not found.')passdef Be_Infected(self,id):#强制阳性for i in range(self.number):if self.Person_Data[i].id == id:self.Person_Data[i].Add_Nuclear_Test(True)passpasspassdef Do_Nuclear_Test(self,id):#默认阴性for i in range(self.number):if self.Person_Data[i].id == id:self.Person_Data[i].Add_Nuclear_Test()passpasspassdef Load_Data(self):with open("Person_Data.csv", mode='r', encoding='utf-8-sig', newline='') as f:reader = csv.reader(f)for i,j in enumerate(reader):index = Person(j[0],j[1])index.Nuclear_Number = j[2]self.Add_Data(index)passpass# with open("Nuclear_Test.csv", mode='r', encoding='utf-8-sig', newline='') as f:#     reader = csv.reader(f)#     for i,j in enumerate(reader):#         print(j[0],j[1],j[2])passdef Save_Data(self):Person_Data_Index = []for i in range(self.number):index = [self.Person_Data[i].name, self.Person_Data[i].id, self.Person_Data[i].Nuclear_Number]Person_Data_Index.append(index)passwith open("Person_Data.csv", mode='w', encoding='utf-8-sig', newline='') as f:f.truncate()writer = csv.writer(f)writer.writerows(Person_Data_Index)pass# Nuclear_Test_Index = []# for i in range(self.number):#     for j in range(int(self.Person_Data[i].Nuclear_Number)):#         # index = [self.Person_Data[i].Nuclear[j].id,self.Person_Data[i].Nuclear[j].time,self.Person_Data[i].Nuclear[j].result]#         print(self.Person_Data[i].Nuclear[j].id)#         # Nuclear_Test_Index.append(index)#         pass# with open("Nuclear_Test.csv", mode='w', encoding='utf-8-sig', newline='')as f:#     f.truncate()#     writer = csv.writer(f)#     writer.writerows(Nuclear_Test_Index)#     pass# passdef Output(self):for i in range(self.number):self.Person_Data[i].Output()passpassdef __del__(self):print('The system is shut down.')pass
People1 = Person('Hu',114514)
People2 = Person('Xi',114515)
A = System()
A.Load_Data()
A.Add_Data(People1)#增
A.Add_Data(People2)#增
A.Be_Infected(114514)#改
A.Do_Nuclear_Test(114514)#查
A.Be_Infected(114515)
A.Do_Nuclear_Test(114515)
A.Find_Data(114514)#查
A.Find_Data(114516)#查
#A.Save_Data()

知识不用罗列,全部呈现在代码中了。

现在我们有一组从2006年到2016年1000部最流行的电影数据,
数据来源:https://www.kaggle.com/damianpanek/sunday-eda/data
(数据是本文件下的 IMDB-Movie-Data)
·问题1:我们想知道这些电影数据中评分的平均分,导演的人数等信息,我们应该怎么获
取?
·问题2∶对于这一组电影数据,如果我们想rating,runtime的分布情况,应该如何呈现数
据?
·问题3∶对于这一组电影数据,如果我们希望统计电影分类(genre)的情况,应该如何处理数据?

问题1

import numpy as np
import pandas as pd
import csv
import matplotlib.pyplot as plt
import matplotlib.font_manager as fmimdb = pd.DataFrame(pd.read_csv('IMDB-Movie-Data.csv'))
rating = imdb['Rating'].values
print('电影数据中评分的平均分 ' , rating.mean())dir=imdb['Director'].values
director = list(set(dir))
print('导演的人数 ',len(director))

问题2

import IMDB
import numpy as np
import pandas as pd
import csv
import matplotlib.pyplot as plt
import matplotlib.font_manager as fmr1=r2=r3=r4=r5=r6=r7=r8=r9=int(0)
for i in range(IMDB.rating.size):if IMDB.rating[i] >= 1 and IMDB.rating[i] < 2:r1 = r1 + 1elif IMDB.rating[i] >= 2 and IMDB.rating[i] < 3:r2 = r2 + 1elif IMDB.rating[i] >= 3 and IMDB.rating[i] < 4:r3 = r3 + 1elif IMDB.rating[i] >= 4 and IMDB.rating[i] < 5:r4 = r4 + 1elif IMDB.rating[i] >= 5 and IMDB.rating[i] < 6:r5 = r5 + 1elif IMDB.rating[i] >= 6 and IMDB.rating[i] < 7:r6 = r6 + 1elif IMDB.rating[i] >= 7 and IMDB.rating[i] < 8:r7 = r7 + 1elif IMDB.rating[i] >= 8 and IMDB.rating[i] < 9:r8 = r8 + 1elif IMDB.rating[i] >= 9 and IMDB.rating[i] < 10:r9 = r9 + 1rat = list(range(1,10))
rating_distribution = [r1,r2,r3,r4,r5,r6,r7,r8,r9]
plt.xlabel('分数',fontproperties='simhei')
plt.ylabel('Rating_Number')
plt.title('rating分布情况',fontproperties='simhei',fontsize=14)
plt.xticks(rat)
plt.bar(rat,rating_distribution)
plt.show()

import IMDB
import numpy as np
import pandas as pd
import csv
import matplotlib.pyplot as plt
import matplotlib.font_manager as fmRuntime = IMDB.imdb['Runtime (Minutes)'].values
runtime = {}
for i in range(Runtime.min(),Runtime.max()+1):runtime[i]=0pass
for i in range(Runtime.size):runtime[Runtime[i]]+=1pass
plt.xlabel('Runtime (Minutes)',fontproperties='simhei')
plt.ylabel('Runtime_Number')
plt.title('Runtime分布情况',fontproperties='simhei',fontsize=14)
plt.bar(runtime.keys(),runtime.values())
plt.show()

Pygame简单入门学习笔记相关推荐

  1. JS简单入门学习笔记一

    JS的HelloWorld 在页面中输出一个内容 document.write(); 向控制台输出一个内容 console.log(); /**1.JS中严格区分大小写*2.JS中每一条语句以分号结尾 ...

  2. linux修改时间_技术干货||基于Centos8的Linux简单入门学习笔记

    很基础 以后不想记笔记了 最后分享一次

  3. Python 简单入门学习笔记

    一.输入输出 print 显示变量内容 例如:print  "hello,world",print("hello,world")  3.0只支持第二种 raw_ ...

  4. 《Java Web开发入门很简单》学习笔记

    <Java Web开发入门很简单>学习笔记 1123 第1章 了解Java Web开发领域 Java Web主要涉及技术包括:HTML.JavaScript.CSS.JSP.Servlet ...

  5. OpenGL入门学习笔记(一)——简单实现FFT海洋

    一.前言 文章不赘述OpenGL的使用入门,使用入门请参考LearnOpenGL CN(https://learnopengl-cn.github.io/). 文章主要参考: [1][学习笔记]Uni ...

  6. Python快速编程入门#学习笔记01# |第一章 :Python基础知识 (Python发展历程、常见的开发工具、import模块导入)

    全文目录 ==先导知识== 1 认识Python 1.1.1 Python的发展历程 1.1.2 Python语言的特点 2. Python解释器的安装与Python程序运行 1.2.1 安装Pyth ...

  7. dubbo入门学习笔记之入门demo(基于普通maven项目)

    注:本笔记接dubbo入门学习笔记之环境准备继续记录; (四)开发服务提供者和消费者并让他们在启动时分别向注册中心注册和订阅服务 需求:订单服务中初始化订单功能需要调用用户服务的获取用户信息的接口(订 ...

  8. 机器学习入门学习笔记:(3.2)ID3决策树程序实现

    前言 之前的博客中介绍了决策树算法的原理并进行了数学推导(机器学习入门学习笔记:(3.1)决策树算法).决策树的原理相对简单,决策树算法有:ID3,C4.5,CART等算法.接下来将对ID3决策树算法 ...

  9. 机器学习入门学习笔记:(2.2)线性回归python程序实现

      上一篇博客中,推导了线性回归的公式,这次试着编程来实现它.(机器学习入门学习笔记:(2.1)线性回归理论推导 )   我们求解线性回归的思路有两个:一个是直接套用上一篇博客最后推导出来的公式:另一 ...

最新文章

  1. ScaleIO 1.32现在可以免费下载安装使用了(除生产环境之外)
  2. zynq学习04 zynq中PS通过MIO控制LED
  3. 用python简单处理图片(2):图像通道\几何变换\裁剪
  4. Python字符串笔录
  5. 网易试题——关于箭头函数与this和arguments的关系
  6. 【转】D365 FO第三方集成(三)---服务实现
  7. VMware vCloud与Zend Server实现PHP应用程序自动化交付
  8. Docker容器commit安装kali工具集
  9. Spring Cloud Alibaba Sentinel之热点参数限流篇
  10. 我经历的学术与论文写作
  11. 史上最强图标下载,3124个图标专辑,超过60万免费图标提供下载
  12. web前端面试过程流程和建议
  13. 火车采集器V9入门之网址采集 实例讲解
  14. java locale zh_国际化:Java平台下的Locale类
  15. 可解释深度学习:从感受野到深度学习的三大基本任务:图像分类,语义分割,目标检测,让你真正理解深度学习
  16. subclass and extends
  17. zend_Zend认证工程师
  18. 机器学习——变分推断
  19. 24、Java——银行存款取款系统(对象+集合)
  20. 针对或者利用计算机网络实施,利用计算机实施财产犯罪定性问题研究

热门文章

  1. eyoucms 指定文章列表如何调用下载内容
  2. 黑暗之魂3正在从服务器获取信息,黑暗之魂3如何解决入侵服务器问题 | 手游网游页游攻略大全...
  3. 基于matlab的talbot效应光栅的计算机模拟[1],基于matlab的talbot效应光栅的计算机模拟.doc...
  4. 一个父亲的智慧:孩子教不好,别总怨社会
  5. 网购秒杀系统架构设计案例分析
  6. [导入]如何学习英语(英语学习中最重要的五点)
  7. Science:中国农业科学院作物科学研究所周文彬团队在水稻中发现单一基因可使水稻显著增产...
  8. 帧同步和状态同步笔记
  9. 使用red5+adobe flash media live encoder搭建存储、流媒体服务器
  10. 「项目管理工具」进度猫如何实现可视化?