# -实验3

import 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)

datas = {'2049777001': ['篮球', '羽毛球', '美食', '漫画'],
'2049777002': ['音乐', '旅行'],
'2049777003': ['马拉松', '健身', '游戏'],
'2049777004': [],
'2049777005': ['足球', '阅读'],
'2049777006': ['发呆', '闲逛'],
'2049777007': [],
'2049777008': ['书法', '电影'],
'2049777009': ['音乐', '阅读', '电影', '漫画'],
'2049777010': ['数学', '推理', '音乐', '旅行']}
l = []
x = []
li = list(datas.values())
for i in li:
for j in i:
l.append(j)
for s in l:
x.append(l.count(s))
d = dict(zip(l,x))
y = sorted(list(d.items()),reverse=True)
for key,value in y:
print(f'{key}:{value}')

temperatures= [['2022-04-18', '星期一', '10', '22'],
['2022-04-19', '星期二', '10', '22'],
['2022-04-20', '星期三', '12', '25'],
['2022-04-21', '星期四', '13', '28'],
['2022-04-22', '星期五', '16', '31'],
['2022-04-23', '星期六', '19', '31'],
['2022-04-24', '星期日', '19', '27']]
x = []
y = []
m = 0
n = 0
for i in range(len(temperatures)):
x.append(int(temperatures[i][2]))
for j in range(len(temperatures)):
x.append(int(temperatures[j][3]))
for s in range(int(len(x)/2)):
m += x[s]
n += x[s+7]
print('未来一周最低气温；{}'.format(min(x)))
print('未来一周最高气温：{}'.format(max(x)))
print('未来一周平均气温区间：{:.0f}-{:.0f}'.format(n/7,m/7))

import random
x = random.randint(1,31)
i = 1
while i<=3:
y = eval(input('输入一个日期:'))
if y < x:
print('日期早了哦')
elif y > x:
print('日期晚了哦')
elif y == x:
print('猜中了！！！')
break
i+=1
if y!=x:
print('正确答案是：{}呢'.format(x))

i = 0
while i < 3:
ls = []
l = []
x, n = eval(input('输入十进制整数和要转换的进制n（2,8,16）:'))
while x > 0:
a = x%n
x = x//n
l.append(a)
for j in l:
ls.append(str(j))
ls.reverse()
s = ''.join(ls)
if i == 2:
s = s.replace('10','A')
print(s)
i+=1

posted @ 2022-04-27 12:28  llzyj  阅读(8)  评论(1编辑  收藏  举报