彩票中心编写一个程序,功能为:随机生成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 ] , "个")
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的值不可能的是( )
s = "Li20An24K04ao" ; i = 0
while i < len( s ) :
if "A" <= s[ i ] <= "Z" :
s = s[ : i ] + s[ i + 1 : ]
elif "0" <= s[ i ] <= "9" :
s = s[ : i ] + str( ( int(s[ i ]) + 8 ) % 10 ) + s[ i + 1 : ]
else :
s = s[ : i ] + chr( ( ord( s[ i ] ) – 95 ) % 26 + 97 ) + s[ i + 1 : ]
i = i + 1
执行上述程序后,s的值为( )
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的值是( )