2024年6月电子学会青少年软件编程(Python六级)等级考试试卷
剩余时间 --:--:--
单选题 共 25 题
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()
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表中哪些人的年龄?( )

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())
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()

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())
6.

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

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

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

      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])
8.

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

9.

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

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

CREAT TABLE Users (id,name,password,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()
12.

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

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()

14.

有如下python程序段:

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

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

15.

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

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

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

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.

18.

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

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的是?( )

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的值可能是?( )

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!

22.

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

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()

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

24.

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

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代码,运行结果是?( )

判断题 共 10 题
1.

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

2.

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

3.

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

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

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

4.

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

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()
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)
7.

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

8.

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

class MyClass(): 
     def my_method(self, other_arg): 
             print(self, other_arg) 
 obj = MyClass() 
 obj.my_method("Hello")
9.

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

10.

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

C++ 编辑器
输入
输出