2023年9月电子学会青少年软件编程(Python六级)等级考试试卷
客观题
六级
2023
2023-10-29 19:36:46
48次
一、单选题
有如下Python程序段:
a=[1,2,3,5,6,8,9,11,15,0] #0表示该位置未存储元素 num=int(input( "输入需要插入的数据:")) for i in range(len(a)): if a[i]>num: for j in range(len(a)-1,i-1,-1): a[j]=a[j-1] a[i]=num break else: a[-1]=num print(a)
执行程序后,输入数字9,则位置下标发生改变的数据个数?( )
| A. 3 |
B. 2 |
| C. 1 |
D. 0 |
【知识点】 电子学会Python六级
运行以下Python代码,结果是?( )
class Person():
def __init__(self, name, age):
self.name = name
self.age = age
def say_hello(self):
print(f"Hello, my name is {self.name}. I am {self.age} years ol")
person1 = Person("Alice", 25)
person2 = Person("Bob", 30)
person1.say_hello() | A. Hello, my name is Alice. I am 25 years ol |
B. Hello, my name is Bo I am 30 years ol |
| C. Hello, my name is Bo I am 25 years ol |
D. Hello, my name is Alice. I am 30 years ol |
【知识点】 电子学会Python六级
编写一个程序,如下图所示,用于计算输入两个数的和,并通过窗口输出计算结果。空白处应补充的代码是?( )

import tkinter as tk import tkinter.messagebox win=tk.Tk() a=tk.IntVar() b=tk.IntVar() def jia(): a1=get() b1=get() tk.messagebox.showinfo(message=str(a1)+'+'+str(b1) +'=' + str(a1+b1)) c=tk.Entry(win,textvariable=a) d=tk.Entry(win,textvariable=b) ok=tk.Button(win,text='+',command=_________) place(x=10,y=10,width=80,height=20) place(x=10,y=40,width=80,height=20) ok.place(x=10,y=80,width=50,height=20) win.mainloop()
| A. add |
B. plus |
| C. jia() |
D. jia |
【知识点】 电子学会Python六级
有如下Python程序段,执行程序后,输出的结果是?( )
import csv
with open('123.csv', 'w',newline='') as f:
w=csv.writer(f)
w.writerows([('hello','world'), ('I','love','you')])
with open('123.csv', 'r') as f:
sp= csv.reader(f)
for row in sp:
print(row[0],end=',') | A. hello,I, |
B. hello,world |
| C. I,you |
D. 程序有误 |
【知识点】 电子学会Python六级
给定以下 Python 代码,连接到一个 SQLite 数据库并查询表 students。请问,查询结果中包含多少个学生?( )
import sqlite3
conn = sqlite3.connect(":memory:")
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
score INTEGER NOT NULL
);
""")
cursor.execute("INSERT INTO students (name, score) VALUES ('小明', 90)")
cursor.execute("INSERT INTO students (name, score) VALUES ('小芳', 85)")
cursor.execute("INSERT INTO students (name, score) VALUES ('轩轩', 92)")
cursor.execute("INSERT INTO students (name, score) VALUES ('乐乐', 88)")
conn.commit()
cursor.execute("SELECT * FROM students WHERE score >= 90")
result = cursor.fetchall()
conn.close()
print(result) | A. 0 |
B. 1 |
| C. 2 |
D. 3 |
【知识点】 电子学会Python六级
假设你正在开发一个电子商务网站,你需要存储用户订单信息。需要创建一个名为 orders 的表,下面哪个 SQL 语句最合适?( )
| A. CREATE TABLE orders (id INTEGER PRIMARY KEY, user_id INTEGER, product_name TEXT, quantity INTEGER, price REAL) |
B. CREATE TABLE orders (user_id INTEGER, product_name TEXT, quantity INTEGER, price REAL) |
| C. CREATE TABLE orders (id INTEGER PRIMARY KEY, user_id INTEGER, product_name TEXT) |
D. CREATE TABLE orders (id INTEGER, user_id INTEGER, product_name TEXT, quantity INTEGER, price REAL) |
【知识点】 电子学会Python六级
执行如下代码:
fname = input("请输入要写入的文件:")
fo = open(fname, "w+")
ls=["清明时节雨纷纷,","路上行人欲断魂,","借问酒家何处有?","牧童遥指杏花村。"]
fo.writelines(ls)
fo.seek(0)
for line in fo:
print(line)
fo.close ()以下选项中描述错误的是?( )
| A. 执行代码时,从键盘输入“清明.txt”,则清明.txt 被创建 |
B. 代码主要功能为向文件写入一个列表类型,并打印输出结果 |
| C. fo.seek(0)这行代码可以省略,不影响输出效果 |
D. fo.writelines(ls)将元素全为字符串的 ls列表写入文件 |
【知识点】 电子学会Python六级
以下哪个Python代码片段正确地执行了一个SQL查询并获取了所有结果?( )
| A. cursor.execute("SELECT * FROM students") results = cursor.scroll() |
B. cursor.execute("SELECT * FROM students") results = cursor.fetchall() |
| C. results = cursor.execute("SELECT * FROM students").fetchone() |
D. cursor.begin("SELECT * FROM students") results = cursor.fetchmany() |
【知识点】 电子学会Python六级
运行以下Python代码,结果是?( )
class Parent():
def __init__(self, name):
self.name = name
def greetings(self):
print("Parent: Hi, I'm", self.name)
class Child(Parent):
def greetings(self):
super().greetings()
print("Child: Hello!")
parent = Parent("Alice")
child = Child("Bob")
chilgreetings() | A. Parent: Hi, I'm Alice Child: Hello! |
B. Parent: Hi, I'm Bo Child: Hello! |
| C. Parent: Hi, I'm Bob |
D. Child: Hello! |
【知识点】 电子学会Python六级

