首页 › 试卷 › Python编程考级 › Python编程三级 › 青少年软件编程(Python三级)等级考试试卷-编程题(2022年3月)

青少年软件编程(Python三级)等级考试试卷-编程题(2022年3月) VIP

Python编程三级 共 3 题 2022 年 含标准答案与解析
返回试卷列表
本页为整卷浏览:先自己做一遍,再展开「查看答案与解析」核对。

一、简答题

1. 简答题

明明请你帮忙寻找100-999之间的所有“水仙花数”,并统计个数。“水仙花数”是指一个三位数各位数字的立方和等于该数本身。

例如:153=1*1*1+5*5*5+3*3*3。要求输出结果如下所示:

153

370

371

407

请编程实现上述功能,补全代码。

for i in range(   ①   ):

   x=i

   a=x % 10

   x= (   ②   )    

   b=x % 10

   c=x // 10

   if (   ③   ):

      print(i)

查看答案与解析
答案:<p>参考程序:</p><p>for i in range(100, 1000):</p><p>    x = i</p><p>    a = x % 10</p><p>    x = x // 10</p><p>    b = x % 10</p><p>    c = x // 10</p><p>    if (a * a * a + b * b * b + c * c * c == i):</p><p>        print(i)</p>
解析:

评分标准:

① 100,1000 或等效答案;(3分)

② x//10 或等效答案;(3分)

③ a*a*a+b*b*b+c*c*c==i 或等效答案。(4分)

2. 简答题

查找“支撑数”。在已知一组整数中,有这样一种数非常怪,它们不在第一个,也不在最后一个,而且刚好都比左边和右边相邻的数大,你能找到它们吗? 输入一个数组,输出每个支撑数的数值以及它们在数组中位置编号。

示例:

输入:

    1 3 2 4 1 5 3 9 7 10 8 23 85 43

输出:

3   2

4   4

5   6

9   8

10   10

85   13

请编写程序实现上述功能,补全代码。

s=input()

x=s.split(' ')

a=[]

for i in range(0,len(x)):

   a.append(int(   ①   )

b=[]

c=[]

n=0

for i in range(1,   ②   ):

   if (a[i]>a[i-1] and   ③   ):

      append(a[i])

      append(   ④   )


for i in range(   ⑤   ):

   print(b[i],' ',c[i])

查看答案与解析
答案:<p>参考程序:</p><pre class="brush:python;toolbar:false">s=input() x=s.split(' ') a=[] for i in range(0,len(x)):    a.append(int(x[i])) b=[] c=[] for i in range(1, len(a)-1):    if (a[i]&gt;a[i-1] and a[i]&gt;a[i+1]):       append(a[i])       append(i+1) for i in range(len(b)):    print(b[i],' ',c[i])</pre><p><br/></p>
解析:

评分标准:

① x[i] 或等效答案;(3分)

② len(a)-1或等效答案;(3分)

③ a[i]>a[i+1] 或等效答案;(4分)

④ i+1 或等效答案;(3分)

⑤ len(b) 或等效答案;(3分)

3. 简答题

请读取某班级语文学科的成绩文件score.txt的数据,数据内容如下图显示:

下列代码实现了读取数据并对每个成绩从小到大排序后并输出,请你补全代码。

with open('/data/   ①   ', 'r') as f:

    list = f.readlines()

for i in range(0, len(list)):

    list[i] = list[i].strip('\n')

    list[i]=  (  ②  )

    (  ③  )

print(list)

f.close

查看答案与解析
答案:<p>参考程序:</p><pre class="brush:python;toolbar:false">with open('/data/score.txt', 'r') as f:     list = f.readlines() for i in range(0, len(list)):     list[i] = list[i].strip('\n')     list[i]=int(list[i]) list.sort() print(list) f.close</pre><p><br/></p>
解析:

评分标准:

(1) score.txt      (1分)

(2) int(list[i])     (1分)

(3) list.sort()     (2分)