s = ['12','22','23','31','123','224']
res =s[0]
for i in range(1,len(s)):
if s[i] >= res:
res =s[i]
print(res)
执行上述程序后,输出的结果是( )
import random
a = [ 0 ] *5 ; i = 0 ; flag = True
while i < 5 :
a[ i ] = random.randint( 1 , 8 )
if i % 2 == 1 :
a[ i ] = a[ i ] + a[ i - 1 ]
flag = not flag
elif a[ i ] % 2 == 0 and flag == False:
i -= 1
i += 1
执行该程序段后,列表a的值不可能的是( )
a = [ 6 , 12 , 9 , 20 , 8 , 11 , 4 ]
for j in range( 1 , len( a ) ) :
if a[ j ] < a[ j - 1 ] :
a[ j ] = a[ j ] + a[ j - 1 ] ; a[ j - 1 ] = a[ j ] - a[ j - 1 ] ; a[ j ] = a[ j ] - a[ j - 1 ]
执行该段程序后,列表a的值是( )
彩票中心编写一个程序,功能为:随机生成7个不重复的中奖号码,并读取文件“彩票记录.txt”(该文件存储所有已售出的彩票号码),最后根据兑奖规则输出开奖结果,运行界面示例如下:
import random #随机生成7个[1,33]范围内不重复的中奖号码
flag= [ 0 ] * 34 ; data = [ 0 ] * 7
i = 0
while i < 7 :
t = random.randint( 1 , 33 )
if not flag[ t ]:
i = i + 1
flag [ t ] = 1
print("中奖号码:" , data)
#读取"彩票记录.txt"文件,存储到数组sale=[[12,8,9,23,1,16,7],[11,7,10,21,2,9,31]…],代码略。
#num[0]表示特等奖个数,num[i]表示i等奖个数
for i in range( len ( sale ) ) :
cnt = 0
for j in range ( 7 ) :
if sale[ i ][ j ] in data:
cnt += 1
num[] += 1
print("彩票开奖结果:")
for i in range( 7 ):
s="特等奖一等奖二等奖三等奖四等奖五等奖六等奖"
print(s[] , "产生:" , num[ i ] , "个")
lst = [2,5,2,1]
y = [1,1,1,1]
n = len(lst)
for i in range(①____):
for j in range(②____):
if ③____:
y[j] = y[j] + 1
else
y[i] = y[i] + 1
上述程序段3个划线处的表达式分别为( )
dic = {"a": [9,12],"b": [8,16]}
dic["a"][1] = 15
dic["c"] = [12,13,11]
s="abc";sum=0
for i in s:
sum += dic[i][1] print(sum)
该程序运行后输出的结果为( )
a=[9, 7, 17, 16, 13, 9, 16, 14, 8, 13]
n=len(a)
p=[False]*n
ans=[]
for i in range(2):
mx=-1
for j in range(n):
if not p[j]:
if mx==-1 or a[j]>a[mx]:
mx=j p[mx]=True
ans.append(a[mx]) print(ans)
程序执行后的输出结果是( )
dict={1:"p",2:"y",3:"t",4:"h",5:"o",6:"n"}
num=[4,2,1,5]
result=""
for i in num:
result+=dict[i]
print(result)
执行该程序段后,result的值为( )