目录
人生苦短,我用Python!
这一次是pygame的期末考试,请认真作答。
一、选择题(每题5分,记25分)
1、下列说法不正确的一项是()
A、pygame.event.get()可以获得当前事件列表。
B、play()方法没有参数。
C、在调用pygame.display.update()前一切绘制只是内存中的内容,不会显示。
D、pygame.time.Clock()可以创建一个时钟对象。
2、小明写了一段代码(见下方),报了错误。小明的代码问题出在哪里?()
import pygame
pygame.init()
screen = pygame.display.set_mode(1500,500)
music = pygame.mixer.Sound("code.wav")
music.play(-1)
A、play()函数参数传递错误 。 B、无法找到code.wav。
C、set_mode()函数参数传递错误。 D、模块使用错误,第四行mixer应该为mixer_sound。
3、这里有一段代码(见下方),编写了一个函数,随后使用时并起到没有作用!原因是()。
import pygame
pygame.init()
screen = pygame.display.set_mode((1500,1000))
def main():
screen.fill((255,255,255))
return
if __name__ == "__main__":
while True:
main()
A、因为并没有达到条件__name__ == "__main__"。
B、return语句影响程序运行。
C、忘记加上pygame.display.update()
D、screen这个域内变量无法使用。
4、小红写了一段代码(如下),发现移动方向与设定不同。问题出在()。
import pygame
pygame.init()
screen=pygame.display.set_mode([500,400])
moveup=movedown=moveleft=moveright=False
picX=picY=0
me=pygame.image.load("run2.png")
timer=pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_UP:
moveup=True
elif event.key==pygame.K_DOWN:
movedown=True
elif event.key==pygame.K_LEFT:
moveleft=True
elif event.key==pygame.K_RIGHT:
moveright=True
elif event.type==pygame.KEYUP:
if event.key==pygame.K_UP:
moveup=False
elif event.key==pygame.K_DOWN:
movedown=False
elif event.key==pygame.K_LEFT:
moveleft=False
elif event==pygame.K_RIGHT:
moveright=False
if moveup:
picY -=10
elif movedown:
picY +=10
elif moveleft:
picX -=10
elif movedown:
picX +=10
screen.fill((0,0,0))
screen.blit(me,(picY,picX))
pygame.display.update()
timer.tick(60)
A、显示图片错误 B、获取事件错误 C、反应错误 D、系统故障
5、下面表格要求,()符合。
窗口大小 | 1500×1000 |
图片 | pic.png |
移动 | 向右移动, 碰到边缘回到左边界 |
A、
import pygame
pygame.init()
screen = pygame.display.set_mode((1500,1000))
pic=pygame.image.load("pic.png")
picX=picY=700
while True:
picX -= 60
if picX <= 0:
picX = 700
screen.fill((0,0,0)
screen.blit(pic,(picX,picY))
pygame.display.update()
B、
import pygame
pygame.init()
screen = pygame.display.set_mode((1500,1000))
pic=pygame.image.load("c.png")
picX=picY=0
while True:
picX += 60
if picX >= 1500:
picX = 0
screen.fill((0,0,0)
screen.blit(pic,(picX,picY))
pygame.display.update()
C、
import pygame
pygame.init()
screen = pygame.display.set_mode((1500,1000))
pic=pygame.image.load("pic.png")
picX=picY=0
while True:
picX += 60
if picX >= 1500:
picX = 0
screen.fill((0,0,0)
screen.blit(pic,(picY,picX))
pygame.display.update()
D、
import pygame
pygame.init()
screen = pygame.display.set_mode((1500,1000))
pic=pygame.image.load("pic.png")
picX=picY=0
while True:
picX += 60
if picX >= 1500:
picX = 0
screen.fill((0,0,0)
screen.blit(pic,(picX,picY))
pygame.display.update()
二、补充代码(每空5分,记50分)
1、
import pygame
pygame.( )
def main():
screen = pygame.display.set_mode((1500,1000))
while True:
( ) event ( ) pygame.event.get():
if event.( ) == ( ).QUIT:
#停止运行main()
( )
if __name__ == 'main':
( ) #运行
pygame.quit()
2、
import pygame
import ( )
pygame.init()
screen = pygame.display.set_mode([800,600])
while True:
for event in pygame.( ).get():
if event.type == pygame.KEYDOWN:
if event.( ) == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
三、统计图(25分)
下面是运-9运输机飞行的时间以及路程的统计表。请根据数据,用pygame画出折线统计图。
1h | 700km |
2h | 1400km |
3h | 2100km |
4h | 2800km |
5h | 3500km |
6h | 4200km |
人生苦短,我用Python!