Python编程六级 题库
使用 tkinter 设置一个按钮,将按钮放置在窗口最下方,则划线处的代码为?()
btn1.pack(side=BOTTOM)
btn1.pack(side='')
side=BOTTOM 由下往上布置。
以只读方式打开 d:\myfile.txt 文件的代码是?()
只读方式:r,不写时,默认为r;打开文本文档默认为t,可以省略,"rt+"与"r+"模式一样,为可读可写模式;"a"为追加模式。
在进行文件读写时,以下为非二进制文件的是?()
文本文件的格式为:txt;二进制文件的格式为:图像、音频、视频、office 文档、可执行性文档等。
下面的程序输出结果是"like",请填空?()

seek(偏移值[,起点]),起点可以省略,0 表示从文件头开始,1 表示从当前位置开始,2 表示从文件尾开始,默认为 0。
with open("example.txt", "a") as file:
file.write("I see you.") 其中example.txt文件内容如下: This is an example.This is an example.
I see you.
This is an example.I see you.
I see you.This is an example.
这行代码使用了`with`语句来打开"example.txt"文件,a用于在文件的结尾追加内容。也就是说,新的内容将会被写入到已有内容之后。
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 AnimalOnce 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.此程序文件名为 “exmaple.txt”。程序使用 with 语句打开文件,在文件的每一行上迭代,并使用计数器 line_count 统计行数。最后,程序输出文件的行数。
在命令行窗口分别运行以下代码,输出结果是?( )
np.full(6,'6')第一个参数指数量。
关于JSON格式数据转为Python数据格式,运行以下程序,输出结果是?( )
age
city
北京
30
json格式数据一个逗号为一组数据,d[2]指第三个数据。
下列哪个选项不能在SQLite数据库中运行?( )
SQLite支持的数据类型包括:NULL、INTEGER、REAL、TEXT、BLOB,分别对应Python的数据类型:None、int、float、str、bytes。
CREAT TABLE Users (id,name,password,role)
关于上述语句,说法错误的是?( )
name作为用户名是不可以重复的。
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()关于以上代码,说法错误的是?( )
conn = sqlite3.connect('./mydb.sqlite'),如果mydb.sqlite不存在会自动创建
cur = conn.cursor(),的作用是获取一个数据的游标
sql = '''INSERT INTO Users (name,password,role) VALUES (?,?,?)'''中?的作用是占位符
运行结果会添加两个admin的管理员账号
用户名admin不能重复。
有如下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的是?( )
dp[m][n]
dp[n][m]
dp[len(dp)-1][0]
dp[m][0]
程序运行结束后, dp的值为[[0, 0, 0], [0, 0, 0], [3, 3, 3],[0, 0, 1]],故选B。
有如下python程序段:
import csv
file=open('data1.csv')
file1=csv.reader(file)
next(file1)
for i in file1:
print(_______)'data1.csv'文件的内容如下图,若要打印每个同学的数学成绩,划线处的代码是?( )

索引2是数学成绩,故选B。
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表中哪些人的年龄?( )
SQL查询中的age > ?与参数(30,)结合,表示查询users表中年龄大于30岁的人。
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代码,运行结果是?( )
在Person类的__init__方法中,self.name和self.age分别被赋值为"Alice"和30。introduce方法返回一个字符串,其中包含这些属性的值。因此,当调用p.introduce()时,返回的字符串将是My name is Alice and I am 30 years old.。
下列代码的输出结果是?( )
100
30
200
400
在MyClass中,我们定义了两个实例变量x和y,并提供了add方法用于返回它们的积。当我们创建MyClass的一个实例并调用add方法时,它返回x和y的乘积,即200。
下列代码中,c.method1()和c.method2()的输出结果分别是?( )
Child's method1
Child's method1
Child's method1
Parent's method1
Parent's method1
Child's method1
Child类重写了Parent类的method1方法,所以c.method1()调用的是Child类中的method1方法,输出"Child's method1"。Child类的method2方法中使用了super().method1()来调用父类Parent的method1方法,因此c.method2()的输出是"Parent's method1"。
下列有关该代码的说法中,不正确的是?( )
创建的类名称为 Jdage
my_stu 为Jdage类的一个对象实例
程序代码执行后的结果为“Peter 已成年。”
def jd(self)的功能是定义jd 函数
def jd(self)的功能是定义jd 操作,而不是函数,因此错误的是 D。
你正在为一个小型游戏设计界面,需要一个按钮,玩家点击后会显示一个消息表示游戏开始。如何绑定一个函数到按钮点击事件,以便在点击时执行?( )
button = Button(root, text="开始游戏", onclick=startGame)
button = Button(root, text="开始游戏", action=startGame)
button = Button(root, text="开始游戏", event=startGame)
在Tkinter中,command 参数用于绑定一个函数到按钮的点击事件。当按钮被点击时,指定的startGame函数将被执行。其他选项提供的属性并不存在于Tkinter的Button类中。