20221328 2022-2023-2 《Python程序设计》实验一报告
课程:《Python程序设计》
班级: 2213
姓名: 马申明
学号:1328
实验教师:王志强
实验日期:2023年5月4日
必修/选修: 公选课
1.实验内容
Python综合应用:爬虫、数据处理、可视化、机器学习、神经网络、游戏、网络安全等。
课代表和各小组负责人收集作业(源代码、视频、综合实践报告)
例如:编写从社交网络爬取数据,实现可视化舆情监控或者情感分析。
例如:利用公开数据集,开展图像分类、恶意软件检测等
例如:利用Python库,基于OCR技术实现自动化提取图片中数据,并填入excel中。
例如:爬取天气数据,实现自动化微信提醒
例如:利用爬虫,实现自动化下载网站视频、文件等。
例如:编写小游戏:坦克大战、贪吃蛇、扫雷等等
注:在Windows/Linux系统上使用VIM、PDB、IDLE、Pycharm等工具编程实现。
2. 实验过程及结果
Flappy Bird代码:
import pygame
import sys
import random
class Bird(object):
def __init__(self):
self.birdRect = pygame.Rect(65,50,50,50)
self.birdStatus = [pygame.image.load("bird2.png"),
pygame.image.load("bird0.png"),
pygame.image.load("birddead1.png")]
self.status = 0
self.birdX = 120
self.birdY = 300
self.jump = False
self.jumpSpeed = 10
self.gravity = 5
self.dead = False
self.strong = False
def birdUpdate(self):
if self.jump:
self.jumpSpeed -= 1
self.birdY -= self.jumpSpeed
else:
self.gravity += 0.2
self.birdY += self.gravity
self.birdRect[1] = self.birdY
class Pipeline(object):
def __init__(self):
self.wallx = 1024
self.wallx2 = 1424
self.wallx3 = 1824
self.wally = 0
self.wally2 = -80
self.wally3 = -50
self.pineUp = pygame.image.load("管道上.jpg")
self.pineDown = pygame.image.load("管道下.jpg")
def updatePipeline(self):
global score
if score <= 30:
self.wallx -= 5
self.wallx2 -= 5
self.wallx3 -= 5
elif score <= 60:
self.wallx -= 7
self.wallx2 -= 7
self.wallx3 -= 7
else:
self.wallx -= 9
self.wallx2 -= 9
self.wallx3