20193427 2019-2020-2 《Python程序设计》实验四报告
课程:《Python程序设计》
班级: 1934
姓名: 杜雨茁
学号:20193427
实验教师:王志强
实验日期:2020年5月23日
必修/选修: 公选课
1.实验内容
Python综合应用:爬虫、数据处理、可视化、机器学习、神经网络、游戏、网络安全等
我选择做一个贪吃蛇小游戏和一个测打字速度的小游戏
测打字速度源代码如下:
import sys
import random
import time
import pygame
from pygame.locals import *
def print_text(font, x, y, text, color=(255, 255, 255)):
imgText = font.render(text, True, color)
screen.blit(imgText, (x, y))
pygame.init()
screen = pygame.display.set_mode((600, 500))
pygame.display.set_caption('Keyboard Demo')
font1 = pygame.font.Font(None, 24)
font2 = pygame.font.Font(None, 200)
white = (255, 255, 255)
yellow = (255, 255, 0)
key_flag = False