实验三

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):
    s2.add(random.randint(1,100))
print(s2)

 

datas = {'2049777001': ['篮球', '羽毛球', '美食', '漫画'],
         '2049777002': ['音乐', '旅行'],
         '2049777003': ['马拉松', '健身', '游戏'],
         '2049777004': [],
         '2049777005': ['足球', '阅读'],
         '2049777006': ['发呆', '闲逛'],
         '2049777007': [],
         '2049777008': ['书法', '电影'],
         '2049777009': ['音乐', '阅读', '电影', '漫画'],
         '2049777010': ['数学', '推理', '音乐', '旅行']
         }
dict={}
for k in datas.values():
    for i in k:
       dict[i] = dict.get(i, 0) + 1
a=sorted(dict.items(),key=lambda x:x[1],reverse=True)
for key,value in a:
    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']]
a=[]
b=[]
for i in temperatures:
    a.append(eval(i[2]))
    l=min(a)
    b.append(eval(i[3]))
    h=max(b)
m=sum(a)//7
n=sum(b)//7
print('未来一周最低气温:{}℃\n未来一周最高气温:{}℃\n未来一周平均气温区间{}℃-{}℃'.format(l,h,m,n))

 

import random
n=random.randint(1,32)
z=0
x=input('五月幸运日:')
while x!=n and z!=2:
     if int(x)<n:
         print('猜早了')
         z += 1
         x = input('五月幸运日:')
     else:
         print('猜晚了')
         z += 1
         x = input('五月幸运日:')
 else:
     if x==n:
         print('猜对了')
     else:
         print(''+str(n))

 

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

 

 

 

 

posted @ 2022-04-28 09:31  q^  阅读(18)  评论(7编辑  收藏  举报