2024年6月电子学会青少年软件编程(Python六级)等级考试试卷
客观题
六级
2024
2024-09-02 14:48:59
85次
一、单选题
下列有关该代码的说法中,不正确的是?( )
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 函数 |
【知识点】 电子学会Python六级
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. 所有人的年龄 |
【知识点】 电子学会Python六级
下列代码中,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 |
【知识点】 电子学会Python六级
已知程序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 |
【知识点】 电子学会Python六级
运行下面代码的正确结果是?( )
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 |
【知识点】 电子学会Python六级
运行下面代码的正确结果是?( )
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. |
【知识点】 电子学会Python六级
你正在为一个小型游戏设计界面,需要一个按钮,玩家点击后会显示一个消息表示游戏开始。如何绑定一个函数到按钮点击事件,以便在点击时执行?( )
| 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) |
【知识点】 电子学会Python六级
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的管理员账号 |
【知识点】 电子学会Python六级
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. |
【知识点】 电子学会Python六级


