2022年9月电子学会青少年软件编程(Python四级)等级考试试卷
操作/编程
四级
2022
2022-11-05 12:37:09
34次
一、单选题
def AddApple(fruit=None):
if fruit is None:
fruit=[]
fruit.append('Apple')
return fruit
AddApple()
AddApple()
print(AddApple(['Pear']))
以上程序段运行的结果是?( )
| A. ['Pear','Apple'] |
B. ['Pear','Apple','Apple'] |
| C. ['Apple','Pear','Apple','Apple'] |
D. ['Apple'] |
【知识点】 电子学会Python四级
下列程序是分治算法的典型应用,其运行结果是?( )
def dividAndConquer(arr,left,right):
if (right == left + 1) or (right == left):
return max(arr[left],arr[right])
mid = int((left + right) / 2)
leftMax = dividAndConquer(arr,left,mid)
rightMax = dividAndConquer(arr,mid,right)
return max(leftMax,rightMax)
arr1 = [8, 1, 14, 19, 5]
print(dividAndConquer(arr1,0,4))
| A. 1 |
B. 19 |
| C. 8 |
D. 5 |
【知识点】 电子学会Python四级
