实验三

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

  

 

 

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

  

 

 

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=[]
for i in temperatures:
    a.append(int(i[2]))
print('未来一周最低气温:' +str(min(a))+'°C')
b=[]
for i in temperatures:
    b.append(int(i[3]))
print('未来一周最高气温:' +str(max(b))+'°C')
print('未来一周平均气温区间: '+str(sum(a)//len(a))+'°C~'+str(sum(b)//len(b))+'°C')

  

 

 

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-25 21:02  一个幽灵  阅读(7)  评论(3编辑  收藏  举报