文档详情

2024年6月青少年软件编程Python等级考试试卷六级真题(含答案)

g***
实名认证
店铺
DOCX
213.50KB
约14页
文档ID:596990703
2024年6月青少年软件编程Python等级考试试卷六级真题(含答案)_第1页
1/14

2024年6月青少年软件编程Python等级考试试卷六级真题(含答案)分数:100 题数:38一、单选题(共25题,共50分)1. 运行下面代码的正确结果是()with open("example.txt", "a") as file: file.write("I see you.")其中example.txt文件内容如下: This is an example.A. This is an example.B. I see you.C. This is an example.I see you.D. I see you.This is an example.标准答案:C2. 在Python中,以下哪个函数可以用于创建一个新的文件()A. write( )B. create( )C. new( )D. open( )标准答案:D3. 运行下面代码的正确结果是()filename = "example.txt"line_count = 0with open(filename, "r") as file: for line in file: line_count += 1print(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.A. 4B. 3C. 2D. 1标准答案:A。

4. 运行下面代码的正确结果是()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.标准答案:B5. 编写程序绘制如下图所示的直线,程序空白处应填()import matplotlib.pyplot as pimport numpy as npx= np.array([0,1,2,____,4,5])p.plot(x,'o:r')p.show()A. 1B. 2C. 3D. 4标准答案:C。

6. 已知程序1绘制的图形如下图所示,要绘制相同的图形,请补全程序2空白()程序1:import matplotlib.pyplot as pimport numpy as npx= np.array([0,1,0,1,0,1,0])p.plot(x,'o:r')p.show()程序2:import matplotlib.pyplot as pimport numpy as npx= np.array([3,4,3,____,3,4,3])p.plot(x,'o:r')p.show()A. 1B. 2C. 3D. 4标准答案:D7. 在命令行窗口分别运行以下代码,输出结果是()>>>import numpy as np>>>np.full(6,'6')A. array(['6', '6', '6', '6', '6', '6']B. array([6, 6, 6, 6, 6, 6]C. 6, 6, 6, 6, 6, 6D. '6', '6', '6', '6', '6', '6'标准答案:A8. 运行以下关于二维数组读取的程序,输出结果是()a=[[1,2,3],[4,5,6],[7,8,9]]print(a[1][2])A. 2B. 4C. 5D. 6标准答案:D。

9. 运行以下代码,绘制出来的第六个柱形图颜色是()import matplotlib.pyplot as pimport numpy as npx=np.array(['a','b','c','d','e','f'])h=np.array([1,4,5,6,4,3])c=np.array(['red','blue','green'])p.bar(x=x,height=h,color=c)p.show()A. redB. blueC. greenD. black标准答案:C10. 关于JSON格式数据转为Python数据格式,运行以下程序,输出结果是()import jsona='{"name": "张三", "age": 30, "city": "北京"}'b=json.loads(a)c=list(b.keys())d=list(b.values())print(d[2])A. ageB. cityC. 北京D. 30标准答案:C11. 下列哪个选项不能在SQLite数据库中运行()A. 10B. '10'C. [10,11]D. None标准答案:C12. CREAT TABLE Users (id,name,password,role)关于上述语句,说法错误的是()。

A. id作为唯一标识,约束条件为PRIMARY和NOT NULLB. name是可以重复的C. password的约束条件为NOT NULLD. role为一个不定长的字符串标准答案:B13. 关于以下代码,说法错误的是()import sqlite3conn = 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','普通用户'))mit()A. conn = sqlite3.connect('./mydb.sqlite'),如果mydb.sqlite不存在会自动创建B. cur = conn.cursor(),的作用是获取一个数据的游标C. sql = '''INSERT INTO Users (name,password,role) VALUES (?,?,?)'''中?的作用是占位符。

D. 运行结果会添加两个admin的管理员账号标准答案:D14. 执行下面程序后,选项中值为1的是()n=3m=2dp=[[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)A. dp[m][n]B. dp[n][m]C. dp[len(dp)-1][0]D. dp[m][0]标准答案:B15. 执行下面程序后,列表a的值可能是()import randoma=[0]*6for i in range(1,6): tmp=random.randint(5,24) if tmp%2==0 or i%2==1: a[i]=a[i-1]+tmpprint(a)A. [0,9,29,50,0,20]B. [1,11,44,62,86,109]C. [0,8,14,21,39,0]D. [0,10,24,43,0,30]标准答案:A16. 题'data1.csv'文件的内容如下图,若要打印每个同学的数学成绩,划线处的代码是()。

import csvfile=open('data1.csv')file1=csv.reader(file)next(file1)for i in file1: print(_______)A. i[1]B. i[2]C. i[3]D. file[2]标准答案:B17. 下面代码会查询users表中哪些人的年龄()import sqlite3conn = 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()A. 年龄等于30的人B. 年龄大于30的人C. 年龄小于30的人D. 所有人的年龄标准答案:B18. 以下代码,运行结果是()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())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.标准答案:A。

19. 下列代码的输出结果是()class MyClass(): def __init__(self): self.x = 10 self.y = 20 def add(self): return self.x * self.yobj = MyClass()。

下载提示
相似文档
正为您匹配相似的精品文档
相关文档