万卷网> 电子学会考级 >Python等级考试 > 2024年6月电子学会青少年软件编程(Python六级)等级考试试卷

2024年6月电子学会青少年软件编程(Python六级)等级考试试卷
客观题 六级 2024 2024-09-02 14:48:59 85

一、单选题

1.

下列有关该代码的说法中,不正确的是?( )

class Jdage():
    def __init__(self,name,age):
        self.name = name
        self.age = age
    def jd(self):
        if self. age<18:
            print(self.name+"还未成年。")
        else:
            print(self.name+"已成年")
my_stu =Jdage("Peter",26)
my_stu.jd()
A.

创建的类名称为 Jdage

B.

my_stu 为Jdage类的一个对象实例

C.

程序代码执行后的结果为“Peter 已成年。”

D.

def jd(self)的功能是定义jd 函数

2.
import sqlite3  
conn = sqlite3.connect('mydatabase.db')  
c = conn.cursor()  
c.execute("SELECT * FROM users WHERE age > ?", (30,))  
results = c.fetchall()  
for row in results:  
    print(row)  
conn.close()

上述代码会查询users表中哪些人的年龄?( )

A.

年龄等于30的人

B.

年龄大于30的人

C.

年龄小于30的人

D.

所有人的年龄

3.

下列代码的输出结果是?( )

class MyClass():  
    def __init__(self):  
        self.x = 10  
        self.y = 20  
  
    def add(self):  
        return self.x * self.y  
  
obj = MyClass()  
print(obj.add())
A.

100

B.

30

C.

200

D.

400

4.

编写程序绘制如下图所示的直线,程序空白处应填?( )

import matplotlib.pyplot as p
import numpy as np
x= np.array([0,1,2,____,4,5])
p.plot(x,'o:r')
p.show()

A.

1

B.

2

C.

3

D.

4

5.

下列代码中,c.method1()和c.method2()的输出结果分别是?( )

class Parent():  
    def method1(self):  
        return "Parent's method1"  
  
class Child(Parent):  
    def method1(self):  
        return "Child's method1"  
      
    def method2(self):  
        return super().method1()  
  
c = Child()  
print(c.method1())  
print(c.method2())
A.

Parent's method1

Parent's method1

B.

Child's method1

Child's method1

C.

Child's method1

Parent's method1

D.

Parent's method1

Child's method1

6.

运行下面代码的正确结果是?( )

with open("example.txt", "a") as file:
    file.write("I see you.")

 其中example.txt文件内容如下:

      This is an example.

A.

This is an example.

B.

I see you.

C.

This is an example.I see you.

D.

I see you.This is an example.

7.

关于JSON格式数据转为Python数据格式,运行以下程序,输出结果是?( )

import json
a='{"name": "张三", "age": 30, "city": "北京"}'
b=json.loads(a)
c=list(b.keys())
d=list(b.values())
print(d[2])
A.

age

B.

city

C.

北京

D.

30

8.

你想创建一个简单的程序,显示一个窗口,用于收集用户的反馈。下列哪个选项是正确的方式来创建一个窗口并运行它?( )

A.

window = Window()

B.

root = Tk()

C.

app = Application()

D.

frame = Frame()

9.

运行以下关于二维数组读取的程序,输出结果是?( )

a=[[1,2,3],[4,5,6],[7,8,9]]
print(a[1][2])
A.

2

B.

4

C.

5

D.

6

10.

CREAT TABLE Users (id,name,password,role)

关于上述语句,说法错误的是?( )

A.

id作为唯一标识,约束条件为PRIMARY 和 NOT NULL

B.

name是可以重复的

password的约束条件为NOT

C.

 NULL

D.

role 为一个不定长的字符串

11.

运行以下代码,绘制出来的第六个柱形图颜色是?( )

import matplotlib.pyplot as p
import numpy as np
x=np.array(['a','b','c','d','e','f'])
h=np.array([1,4,5,6,4,3])
c=np.array(['red','blue','green'])
p.bar(x=x,height=h,color=c)
p.show()
A.

red

B.

blue

C.

green

D.

black

12.

你正在开发一个图书管理系统,需要在界面上显示“书名”这个词。如何添加一个标签控件到你的窗口中显示文本“书名”?( )

A.

word = Word(root, text='书名')

B.

text = Text(root, value='书名')

C.

message = Message(root, text='书名')

D.

label = Label(root, text='书名')

13.

已知程序1绘制的图形如下图所示,要绘制相同的图形,请补全程序2空白?( )

程序1:

import matplotlib.pyplot as p
import numpy as np
x= np.array([0,1,0,1,0,1,0])
p.plot(x,'o:r')
p.show()

程序2:

import matplotlib.pyplot as p
import numpy as np
x= np.array([3,4,3,____,3,4,3])
p.plot(x,'o:r')
p.show()

A.

1

B.

2

C.

3

D.

4

14.

有如下python程序段:

import csv
file=open('data1.csv')
file1=csv.reader(file)
next(file1)
for i in file1:
    print(_______)

'data1.csv'文件的内容如下图,若要打印每个同学的数学成绩,划线处的代码是?( )

A.

i[1]

B.

i[2]

C.

i[3]

D.

file[2]

15.

在命令行窗口分别运行以下代码,输出结果是?( )

>>>import numpy as np
>>>np.full(6,'6')
A.

array(['6', '6', '6', '6', '6', '6']

B.

array([6, 6, 6, 6, 6, 6]

C.

6, 6, 6, 6, 6, 6

D.

'6', '6', '6', '6', '6', '6'

16.

在一个注册界面中,你需要将一个按钮放置在窗口的底部中央。下列哪个布局管理器最适合实现这个需求?( )

A.

pack()

B.

grid()

C.

place()

D.

align()

17.

运行下面代码的正确结果是?( )

filename = "example.txt"
line_count = 0
with open(filename, "r") as file:
     for line in file:
         line_count += 1
print(f"The file 'example' has {line_count} lines.")

  其中example.txt文件内容如下:

      My Favorite Animal

Once upon a time, I had a pet dog named Max. 

Max was the most obedient dog I knew. 

We played fetch in the park, went on long walks in the woods, and even took naps together on lazy afternoons.

A.

4

B.

3

C.

2

D.

1

18.

在 Python 中,以下哪个函数可以用于创建一个新的文件?( )

A.

write( )

B.

create( )

C.

new( )

D.

open( )

19.

有如下python程序段:

n=3
m=2
dp=[[0 for i in range(n)]for j in range(m)]
dp.append([0,0,n-m])
dp.insert(-1,[n for i in range(n)])
print(dp)

执行程序后,下列选项中值为1的是?( )

A.

dp[m][n]

B.

dp[n][m]

C.

dp[len(dp)-1][0]

D.

dp[m][0]

20.

有如下python程序段:

import random
a=[0]*6
for i in range(1,6):
    tmp=random.randint(5,24)
    if tmp%2==0 or i%2==1:
        a[i]=a[i-1]+tmp
print(a)

执行程序后,列表a的值可能是?( )

A.

[0,9,29,50,0,20]

B.

[1,11,44,62,86,109]

C.

[0,8,14,21,39,0]

D.

[0,10,24,43,0,30]

21.

运行下面代码的正确结果是?( )

with open("myfile.txt", "w") as out_file:
    out_file.write("This is my first Python program.")
with open("myfile.txt", "r") as in_file:
    myfile = in_file.read()
print(myfile)

其中myfile.txt文件内容如下:

          Hello World!

A.

Hello World!

B.

This is my first Python program.

C.

Hello World!

This is my first Python program.

D.

Hello World!This is my first Python program.

22.

你正在为一个小型游戏设计界面,需要一个按钮,玩家点击后会显示一个消息表示游戏开始。如何绑定一个函数到按钮点击事件,以便在点击时执行?( )

A.

button = Button(root, text="开始游戏", command=startGame)

B.

button = Button(root, text="开始游戏", onclick=startGame)

C.

button = Button(root, text="开始游戏", action=startGame)

D.

button = Button(root, text="开始游戏", event=startGame)

23.
import sqlite3
conn = sqlite3.connect('./mydb.sqlite')
cur = conn.cursor()
sql = '''INSERT INTO Users (name,password,role) VALUES (?,?,?)'''
cur.execute(sql,('admin','123456','管理员'))
cur.execute(sql,('admin','123456','管理员'))
cur.execute(sql,('user','123456','普通用户'))
conn.commit()

关于以上代码,说法错误的是?( )

A.

conn = sqlite3.connect('./mydb.sqlite'),如果mydb.sqlite不存在会自动创建

B.

cur = conn.cursor(),的作用是获取一个数据的游标

C.

sql = '''INSERT INTO Users (name,password,role) VALUES (?,?,?)'''中?的作用是占位符

D.

运行结果会添加两个admin的管理员账号

24.

下列哪个选项不能在SQLite数据库中运行?( )

A.

10

B.

'10'

C.

[10,11]

D.

None

25.
class Person():  
    def __init__(self, name, age):  
        self.name = name  
        self.age = age  
  
    def introduce(self):  
        return f"My name is {self.name} and I am {self.age} years old."  
p = Person("Alice", 30)  
print(p.introduce())

以上Python代码,运行结果是?( )

A.

My name is Alice and I am 30 years old.

B.

My name is Person and I am 30 years old.

C.

My name is Alice and I am 0 years old.

D.

My name is 30 and I am Alice years old.

二、判断题

1.

json.dumps() 用于将 Python 对象编码成 JSON 字符串。( )

A.正确 B.错误
2.

json.loads()用于将json字符串恢复成Python对象。( )

A.正确 B.错误
3.

下面代码的输出结果是:Hello World! ( )

file = open("exam.txt")
    print(file)
file.close()

其中exam.txt文件内容为:Hello World!

A.正确 B.错误
4.

你正在为一个小型的图书管理系统设计界面,其中包括一个“添加图书”按钮,用户点击后可以将新书信息添加到系统中。点击Button控件可以触发一个函数或方法。( )

A.正确 B.错误
5.

阅读以下代码,请问图表中会显示2条曲线。( )

import matplotlib.pyplot as plt  
import numpy as np  
x = np.linspace(0, 10, 100)  
y1 = np.sin(x)  
y2 = np.cos(x)  
plt.plot(x, y1, label='sin(x)')  
plt.plot(x, y2, label='cos(x)')  
plt.legend()  
plt.show()
A.正确 B.错误
6.

下列代码的输出结果是5。( )

class A():  
    def __init__(self):  
        self.value = 10  
class B(A):  
    def __init__(self):  
        super().__init__()  
        self.value += 5  
b = B()  
print(b.value)
A.正确 B.错误
7.

在Python中,可以使用 with 语句来自动关闭一个文件。( )

A.正确 B.错误
8.

下列Python代码中,self参数的作用表示MyClass类的一个实例。 ( )

class MyClass(): 
     def my_method(self, other_arg): 
             print(self, other_arg) 
 obj = MyClass() 
 obj.my_method("Hello")
A.正确 B.错误
9.

sqlite3.connect('路径/文件名'),如果文件不存在,connect函数会自动创建这个数据库文件。( )

A.正确 B.错误
10.

在Python的matplotlib库中,plt.scatter()函数可用来绘制散点图。( )

A.正确 B.错误
公众号
客服 反馈
顶部