首页 › 题库 › Python编程考级 › Python编程六级

Python编程六级 题库

共 604 道题 ,第 6 / 31 页 · 按题型筛选,点「查看答案」核对解析
101 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

运行以下程序,输出的结果是?( )

class A():
    def __init__(self,x):
        self.x=x+1
    def b(self):
       return self.x*self.x
t=A(3)
print(t.b())
A
9
B
12
C
7
D
16
答案与解析
正确答案:D
这道题暂未补解析。
题目详情
102 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

运行以下程序,输出的结果是?( )

import sqlite3
conn = sqlite3.connect('t1.db')
cursor = conn.cursor()
conn.execute("DELETE from user")
cursor.execute('insert into user (id, name) values (\'1\', \'张三\')')
cursor.execute('insert into user (id, name) values (\'2\', \'李四\')')
cursor.execute('insert into user (id, name) values (\'3\', \'王二\')')
cursor.execute('insert into user (id, name) values (\'4\', \'刘五\')')
conn.commit()
cursor.execute('select id,name from user')
values = cursor.fetchone()
values = cursor.fetchone()
print(values)
cursor.close()
conn.close()
A
('4', '刘五')
B
('1', '张三')
C
('2', '李四')
D
('3', '王二')
答案与解析
正确答案:C
这道题暂未补解析。
题目详情
103 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

以下SQLite语句可以修改记录的是?( )

A
cursor.execute('insert into user (id, name) values (\'1\', \'张三\')')
B
cursor.execute('update user set name = "吴吴" WHERE ID = 4')
C
cursor.execute('select id,name from user')
D
conn.execute("DELETE from user")
答案与解析
正确答案:B
这道题暂未补解析。
题目详情
104 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

SQLite函数中,以下语句的作用是?( )

values = cursor.fetchmany(2)
print(values)
A

输出前两条记录

B

输出第2条记录

C

输出后两条记录

D

输出中间两条记录

答案与解析
正确答案:A
这道题暂未补解析。
题目详情
105 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

关于SQLite,说法错误的是?( )

A

commit()功能是提交当前的所有事务。如果没有提交,程序自上次提交后的所有操作是不可见的

B

execute()功能是执行SQL语句

C

fetchall()功能是获取查询结果中所有的记录,返回类型为列表

D

close()功能是关闭数据库连接,将自动调用commit()以保存所有更改

答案与解析
正确答案:D
这道题暂未补解析。
题目详情
106 单选题 适中 Python编程考级 ·Python编程六级 · 1.3 创建类与子类

有一个叫做Animal的类,请问下面哪个选项是正确的创建子类Cat的语法?( )

A
class Cat(Animal):
B
class Cat extends Animal:
C
class Cat inherits Animal:
D
class Cat is Animal:
答案与解析
正确答案:A
这道题暂未补解析。
题目详情
107 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

下面的代码定义了一个Circle类,用于表示圆形的信息。请问执行下面的代码后,会输出什么?( )

class Circle():
    def __init__(self, radius):
        self.pi=3.14
        self.radius = radius   #半径
    def area(self): #面积
        return  self.pi * self.radius ** 2
    def perimeter(self):   #周长
        return 2 *  self.pi * self.radius
c = Circle(4)
print(c.area())
print(c.perimeter())
A

25.12

50.24

B

没有输出

C

50.24

25.12

D

会报错

答案与解析
正确答案:C
这道题暂未补解析。
题目详情
108 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

下面哪个代码可以创建一个名为cat的实例,属于Animal类,有color和sound两个属性,分别赋值为"black"和"meow"?( )

A
cat = Animal()
B
cat = Animal() cat.color = "black" cat.sound = "meow"
C
cat.color = "black"cat.sound = "meow" cat = Animal()
D
cat = new Animal() cat.color = "black"cat.sound = "meow"
答案与解析
正确答案:B
这道题暂未补解析。
题目详情
109 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

以只读的方式打开文本文件‘a.txt’的代码是?( )

A

f=open('a.txt','r')

B

f=open('a.txt','w')

C

f=open('a.txt','a')

D

f=open('a.txt','r+')

答案与解析
正确答案:A
这道题暂未补解析。
题目详情
110 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

有如下Python代码:

f=open('RGB.txt','r')
a=f.readlines()

代码中变量a的数据类型是?( )

A

字符串

B

数组

C

元组

D

列表

答案与解析
正确答案:D
这道题暂未补解析。
题目详情
111 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

文本文件'a.txt'为空文件,执行以下Python后,'a.txt'文件中的内容是?( )

n=1
f=open('a.txt','a')
while n<=6:
    f.write(str(n))
    n+=1
f.close()
A

123456

B

6

C

空

D
1
答案与解析
正确答案:A
这道题暂未补解析。
题目详情
112 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

文件a.txt中的内容如图所示:

执行如下Python代码,输出的结果是?( )

s=0
with open('a.txt') as f:
    a=f.readlines()
for i in a:
    if len(i)>3:
        s+=1
print(s)
A
1
B
2
C
3
D
4
答案与解析
正确答案:B
这道题暂未补解析。
题目详情
113 单选题 适中 Python编程考级 ·Python编程六级 · 2.1 概念与特性

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

import numpy as np
x = np.array([1, 2, 3, 4, 5])
print(x[2:4])
A

[3 4]

B

[2 3]

C

[2 3 4]

D

[2 4]

答案与解析
正确答案:A
这道题暂未补解析。
题目详情
114 单选题 适中 Python编程考级 ·Python编程六级 · 2.1 概念与特性

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

import numpy as np
arr = np.array([[1, 2],
                      [3, 4]])
print(arr.sum())
A

3

B

4

C

6

D

10

答案与解析
正确答案:D
这道题暂未补解析。
题目详情
115 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

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

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
plt.subplot(2, 1, 1)
plt.plot(x, y1)
plt.xlabel('x轴')
plt.ylabel('y1轴')
plt.subplot(2, 1, 2)
plt.scatter(x, y2, color='r')
plt.xlabel('x轴')
plt.ylabel('y2轴')
plt.tight_layout()
plt.show()
A

显示一个子图,包含一个包含折线图的区域和一个包含散点图的区域

B

显示一个子图,包含一个包含折线图和散点图的混合图形

C

显示两个子图,分别包含折线图和散点图

D

不显示任何内容

答案与解析
正确答案:C
这道题暂未补解析。
题目详情
116 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

下面代码的输出,最合理的选项结果是?( )

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.xlabel('x轴')
plt.ylabel('y轴')
plt.title('简单折线图')
plt.show()
A

显示一个简单的折线图

B

显示一个已经标注了标题、x轴和y轴标签的简单折线图

C

显示一个已经标注了 x 轴和 y 轴标签的简单折线图

D

不显示任何内容

答案与解析
正确答案:B
这道题暂未补解析。
题目详情
117 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

以下Python代码为在tk上绘制一个图形,请问绘制的图形是?( )

import tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, width=300, height=300)
canvas.create_rectangle(100, 100, 200, 200, outline="red")
canvas.pack()
root.mainloop()
A
100*200的矩形
B
300*300的矩形
C
100*100的矩形
D
200*100的矩形
答案与解析
正确答案:C
这道题暂未补解析。
题目详情
118 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

有如下Python代码,如图状态下,点击提交按钮,文本框内显示的内容为?( )

import tkinter as tk
def show_selected_option():
    selection = variable.get()
    p={1:"篮球",2:"排球", 3:"足球"}
    label.config(text=f"最喜欢的运动是 {p[selection]}")
root = tk.Tk()
options = [("篮球", 1), ("排球", 2), ("足球", 3)]
variable = tk.IntVar()
for text, value in options:
    tk.Radiobutton(root, text=text, variable=variable, value=value).pack()
button = tk.Button(root, text="提 交", command=show_selected_option)
label = tk.Label(root, text="最喜欢的运动是什么?")
button.pack()
label.pack()
root.mainloop()
A
最喜欢的运动是排球
B
最喜欢的运动是篮球
C
最喜欢的运动是足球
D
最喜欢的运动是2
答案与解析
正确答案:A
这道题暂未补解析。
题目详情
119 单选题 适中 Python编程考级 ·Python编程六级 · 1.1 类与实例

在tkinter中添加一个按钮的代码是?( )

A
button = tk.Label(root, text="Hello")
B
button = tk.Entry(root)
C
button = tk.Button(root, text="Click")
D
button = tk.Checkbutton(root, text="Check me")
答案与解析
正确答案:C
这道题暂未补解析。
题目详情
120 单选题 适中 Python编程考级 ·Python编程六级 · 1.2 属性与方法

在tkinter中设置控件widget的背景颜色改为红色的方法是?( )

A
`widget.bg_color = "red"`
B
`widget.background = "red"`
C
`widget.set_bg_color("red")`
D
`widget.config(bg="red")`
答案与解析
正确答案:D
这道题暂未补解析。
题目详情