当前位置: 高中信息技术 / 单选题
  • 1. (2022·浙江模拟) 生成一个元素个数为6、元素的值在1~9之间且不重复的数组a,Python代码如下:

    import random

    n=9

    b=[[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,-1]]

    head=0

    a=[]

    for i in range(6):

        k=random.randint(0,n-i-1)

        if k==0:

            a.append(b[head][0])

              ① 

        else:

            p=head

            for j in range(k):

                pre=p

                p=b[p][1]

                a.append(b[p][0])

                   ②   

    划线处应填入的代码为(   )

    A . ①head=b[head][1]       ②b[pre][1]=p B . ①head=b[0][1]          ②b[pre][1]=p C . ①head=b[0][1]          ②b[pre][1]=b[p][1] D . ①head=b[head][1]       ②b[pre][1]=b[p][1]

微信扫码预览、分享更方便