彩票中心编写一个程序,功能为:随机生成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的值是( )
图 a | 图 b |
import pandas as pd
import matplotlib.pyplot as plt
#读取如图 b 所示数据,保存到 DataFrame 对象 df1 中,代码略
f = [9, 7, 6, 5, 4, 3, 2, 1]
for i in range(0,len(dfl)):
rank = df1.at[i,"名次"] #通过行、列标签取单个值
score = 0
if rank <= 8:
df1.at[i,"得分"] = score
df2 = dfl.groupby(" ▲ ",as_index=False).sum() #分组求和
#设置绘图参数,代码略
plt.bar(x,y) #绘制柱形图
①请在程序中划线处填入合适的代码。
②程序的方框中应填入的正确代码为 (单选,填字母)
A.x = df1["专业"]
y = df1["总分"]
B.x = df2["专业"]
y = df2["得分"]
C.df1["专业"] = "专业"
df1["总分"] = "总分"
D.Df2["专业"] = "专业"
Df2["得分"] = "得分"