选择题 共25道
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25判断题 共10道
26 27 28 29 30 31 32 33 34 35编程题 共3道
36 37 38279 | 202403Python六级真题-练习
选择题 共25道
01
以下选项中,创建类正确的是?()
2分
02
运行以下程序,输出结果是?()
class A():
def__init__(self,x):
self.x=x
def add1(self):
return self.x+self.x
t1=A(3)
t2=A(t1.add1())
print(t2.add1())
2分
03
运行以下程序,输出的结果是?()
class T():
def__init__(self):
self.a=1
def t1(self,b):
self.a=b+b
c=T()
c.a=c.a+c.a
c.t1(5)
print(c.a)
2分
04
要将一个数组[1,2,3,4,5]绘制成折线图,代码是?()
2分
05
要生成一个3*4的数组,并计算数组中偶数值之和,代码是?()
2分
06
在使用matplotlib库绘制图形时,如何设置x轴和y轴的标签?()
2分
07
关于matplotlib函数的功能,下列描述错误的是?()
2分
08
下列哪个选项是有效的JSON格式?()
2分
09
下列关于数据的说法,不正确的是?()
2分
10
下面代码的输出结果正确的是?()
import json
json_str='{"name":"Alice","age":25,"city":"New York"}'
data=json.loads(json_str)
print(data)
2分
11
下面代码的输出结果正确的是?()
import json
data={
"name":"Alice",
"age":25,
"city":"New York"
}
text=json.dumps(data)
print(text)
2分
12
有关JSON(JavaScript Object Notation)的概念,正确的是?()
2分
13
使用tkinter设置一个按钮,将按钮放置在窗口最下方,则划线处的代码为?()
from tkinter import*
root=Tk()
root.geometry('300x200')
root.title('my window')
btn1=Button(root,text='按钮1',bg='red')
__________
root.mainloop()
2分
14
以下代码实现将鼠标移到按钮上时按钮变红,鼠标移开时按钮变蓝,划线处的代码是?()
from tkinter import*
root=Tk()
root.title()
root.geometry('450x350')
btn1=Button(root,text='1')
btn1.place(x=200,y=50,width=40,height=40)
def changebg(event):
#鼠标移到按钮上按钮变红
event.widget['bg']='red'
def changebg1(event):
#鼠标离开按钮上按钮变蓝
event.widget['bg']='blue'
____________
btn1.bind('',changebg1)
root.mainloop()
2分
15
以下代码实现点击“点我”按钮,弹出信息“give flower”,划线处的代码是?()
import tkinter as tk
import tkinter.messagebox
from tkinter import*
root=Tk()
bt=Button(root)
bt['text']='点我'
bt.pack()
def dianji(event):
tk.messagebox.showinfo('message','give flower')
bt.bind('<Button-1>',)
root.mainloop()
2分
16
使用tkinter模块,下列代码能创建一个输入框的是?()
2分
17
执行以下代码,数据表中共有几条数据?()
import sqlite3
conn=sqlite3.connect('student_info.db')
cursor=conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS Student
(id INTEGER PRIMARY KEY,name TEXT,age INTEGER)''')
cursor.execute("INSERT INTO Student(id,name,age)VALUES(1,'Alice',20)")
cursor.execute("INSERT INTO Student(id,name,age)VALUES(2,'Bob',22)")
cursor.execute("INSERT INTO Student(id,name,age)VALUES(3,'Charlie',21)")
cursor.execute("SELECT*FROM Student")
students=cursor.fetchall()
for student in students:
print(f"ID:{student[0]},Name:{student[1]},Age:{student[2]}")
cursor.execute("UPDATE Student SET age=23 WHERE id=2")
cursor.execute("DELETE FROM Student WHERE id=3")
conn.commit()
conn.close()
2分
18
如下代码创建一个数据库表,表内有几个字段?()
import sqlite3
connection=sqlite3.connect('test.db')
cursor=connection.cursor()
cursor.execute('''CREATE TABLE employees
(id INTEGER PRIMARY KEY,name TEXT,age INTEGER,salary REAL)''')
connection.close()
2分
19
以下哪个代码片段用于创建一个SQLite数据库mydatabase连接?()
2分
20
运行以下代码输出的数据为?()
import sqlite3
connection=sqlite3.connect("students.db")
cursor=connection.cursor()
cursor.execute("CREATE TABLE students(name TEXT,age INTEGER)")
cursor.execute("INSERT INTO students VALUES('John',19)")
cursor.execute("INSERT INTO students VALUES('John',18)")
cursor.execute("DELETE FROM students WHERE name='John'")
cursor.execute("INSERT INTO students VALUES('John',17)")
cursor.execute("UPDATE students SET age=22 WHERE name='John'")
cursor.execute("SELECT*FROM students")
results=cursor.fetchall()
for row in results:
print(row)
connection.close()
2分
21
以只读方式打开d:\myfile.txt文件的代码是?()
2分
22
在进行文件读写时,以下为非二进制文件的是?()
2分
23
程序填空:程序的输出结果如下图所示,程序空白处应该是?()
我喜欢编程
我喜欢Py
with open("./text.txt","r",encoding='utf-8')as f:
a=f.read()
print(a)

2分
