实验三

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)

问题1:1-99,不能

问题2:0-4,否

             1-4,否

问题3:不一定

问题4:一定

datas = {'2049777001': ['篮球', '羽毛球', '美食', '漫画'],
         '2049777002': ['音乐', '旅行'],
         '2049777003': ['马拉松', '健身', '游戏'],
         '2049777004': [],
         '2049777005': ['足球', '阅读'],
         '2049777006': ['发呆', '闲逛'],
         '2049777007': [],
         '2049777008': ['书法', '电影'],
         '2049777009': ['音乐', '阅读', '电影', '漫画'],
         '2049777010': ['数学', '推理', '音乐', '旅行']
         }
a = list(datas.values())
b = []
for i in a:
    for j in i:
        b.append(j)
c = {}
for k in b:
         c[k] = b.count(k)
d = list(c.items())
e = sorted(d, key=lambda x: x[1], reverse=True)
for m, n in e:
     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']]
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
count = 2
answer = random.randint(1,31)
print('猜猜2022年5月哪一天会是你的lucky day:-')
temp = (input('你有三次机会,猜吧(1~31):'))
while count > 0:
    guess = int(temp)
    if guess == answer:
        print('哇,猜中了。')
        break
    else:
        if int(answer) > int(temp):
            print('猜早啦,你的lucky day还没到呢')
            temp = input('再猜(1~31):')
        else:
            print('猜晚啦,你的lucky day已经过啦')
            temp = input('再猜(1~31):')
    count = count - 1
print('次数用光啦,')
print('偷偷告诉你,5月你的lucky day是{}号.good luck:-'.format(answer))

m, n = eval(input("输入十进制整数和要转换的进制n(2或8或16): "))
a = m
x = []
y = ["A", "B", "C", "D", "E", "F"]
while m != 0:
    p = m % n
    if n == 16:
        if p > 9:
            b = p%10
            p = y[b]
    x.append(p)
    m = m // n
x.reverse()
z = "".join("%s" % i for i in x)
print('{}的{}进制是:{}'.format(m,n,z))

 

posted @ 2022-04-25 14:44  卞康耀  阅读(11)  评论(2编辑  收藏  举报