Pygame第八课:期末考试

目录

一、选择题(每题5分,记25分)

二、补充代码(每空5分,记50分)

三、统计图(25分)


人生苦短,我用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画出折线统计图。

1h700km
2h1400km
3h2100km
4h2800km
5h3500km
6h4200km

人生苦短,我用Python! 

  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值