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

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

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']]
low=[int(id1[2]) for id1 in temperatures]
high=[int(id2[3]) for id2 in temperatures]
print(f"未来一周最低气温:{min(low)}°C")
print(f"未来一周最高气温:{max(high)}°C")
print(f"未来一周平均气温区间:{int(sum(low)/len(low))}°C ~ {int(sum(high)/len(high))}°C")

from random import *
def cai(x):
    if x > aaa:
        return "猜晚啦,你的lucky day已经过啦\n再猜(1~31):"
    elif x < aaa:
        return "猜早啦,你的lucky day还没到呢\n再猜(1~31):"
    else:
        return "哇,猜中了:-)"
aaa, i = randint(1, 31), 0
bbb = int(input("猜猜2022年5月那一天会是你的lucky day:-)\n你有三次机会,猜吧(1~31):"))
while bbb != "哇,猜中了:-)" and i < 2:
    bbb, i = int(input(cai(bbb))), i + 1
    if i == 2: print(f"次数用光了\n偷偷告诉你,5月你的lucky day是{aaa}号,good luck:—)")

x, old_code = eval(input("输入十进制整数x:")), []
n, s = eval(input("输入需要转换的进制:")), x
while x // n != 0:
    old_code.append(x % n)
    x = x // n
    if x // n == 0: old_code.append(x % n)
new_code = list(str(i) if i < 10 else chr(i + 55) for i in old_code[::-1])
print(f"{s}的{n}进制是:" + "".join(new_code))

 

posted @ 2022-04-25 11:44  王景如  阅读(13)  评论(3编辑  收藏  举报