# 实验三

1import random
print('用列表存储随机整数：')
ls = [random.randint(1,100) for i in range(5)]
print(ls)

print('\n用集合存储随机整数：')
s1 = {random.randint(1,100) for i in range(5)}
print(s1)

print('\n用集合存储随机整数：')
s2 = set()
while(len(s2)<5):
print(s2)

1-99 不能

0-4 不包括

1-4 不包括

 1 datas = {'2049777001': ['篮球', '羽毛球', '美食', '漫画'],
2          '2049777002': ['音乐', '旅行'],
3          '2049777003': ['马拉松', '健身', '游戏'],
4          '2049777004': [],
5          '2049777005': ['足球', '阅读'],
6          '2049777006': ['发呆', '闲逛'],
7          '2049777007': [],
8          '2049777008': ['书法', '电影'],
9          '2049777009': ['音乐', '阅读', '电影', '漫画'],
10          '2049777010': ['数学', '推理', '音乐', '旅行']
11          }
12 a=[]
13 b=dict()
14 for i in datas:
15     for j in datas[i]:
16         a.append(j)
17 for i in list(set(a)) :
18     b.update({i:a.count(i)})
19 b=sorted(b.items(),key=lambda x:x[1],reverse=True)
20 for i in b:
21     print(str(i[0])+':'+str(i[1]))

 1 temperatures = [['2022-04-18', '星期一', '10', '22'],
2                 ['2022-04-19', '星期二', '10', '22'],
3                 ['2022-04-20', '星期三', '12', '25'],
4                 ['2022-04-21', '星期四', '13', '28'],
5                 ['2022-04-22', '星期五', '16', '31'],
6                 ['2022-04-23', '星期六', '19', '31'],
7                 ['2022-04-24', '星期日', '19', '27']]
8 a=[]
9 for i in temperatures:
10     a.append(int(i[2]))
11 print('未来一周最低气温:' +str(min(a))+'°C')
12 b=[]
13 for i in temperatures:
14     b.append(int(i[3]))
15 print('未来一周最高气温:' +str(max(b))+'°C')
16 print('未来一周平均气温区间: '+str(sum(a)//len(a))+'°C~'+str(sum(b)//len(b))+'°C')

 1 import random
2 n=random.randint(1,32)
3 z=0
4
5 x=input('五月幸运日:')
6 while x!=n and z!=2:
7     if int(x)<n:
8         print('猜早了')
9         z += 1
10         x = input('五月幸运日:')
11     else:
12         print('猜晚了')
13         z += 1
14         x = input('五月幸运日:')
15 else:
16     if x==n:
17         print('猜对了')
18     else:
19         print('是'+str(n))

 1 x, n = eval(input("输入:"))
2 y=x
3 z=[]
4 d=["A", "B", "C", "D", "E", "F"]
5 while x != 0:
6     p = x % n
7     if n == 16:
8         if p > 9:
9             b = p%10
10             p = y[b]
11     z.append(p)
12     x=x // n
13 z.reverse()
14 t= "".join("%s" % i for i in z)
15 print('{}的{}进制是:{}'.format(y,n,t))

posted @ 2022-04-25 17:52  pray4hell  阅读(12)  评论(3编辑  收藏  举报