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=[i[2] for i in temperatures]
b=[i[3] for i in temperatures]
max=max(b)
min=min(a)
sum1=0
sum2=0
for c in a:
sum1=sum1+int(c)
for d in b:
sum2=sum2+int(d)
a1=int(sum1)//7
a2=int(sum2)//7
print('未来一周最低气温:{}℃'.format(min))
print('未来一周最高气温:{}℃'.format(max))
print('未来一周平均气温区间: {}°C ~ {}°C'.format(a1,a2))

 

 

import random
a=random.randint(1,31)
print('猜猜2022年5月哪天是你的lucky day:')
count=0
while (count<3):
x = int(input('你有三次机会,猜吧(1-31):'))
if x==a:
print('哇,猜中啦')
break
elif x < a:
print('猜早啦,你的lucky day 还没到呢')
else:
print('猜晚了,你的lucky day 已经过啦')
count += 1
if count==3:
print('次数用完啦.')
print('偷偷告诉你,5月你的lucky day 是{}号。 good luck!'.format(a))

 

 

x,y = eval(input("输入十进制整数x和要转换的进制n(2或8或16):"))
list=[]
a=x//y
b=x%y
list.append(b)
while a!=0:
list.append(a%y)
a=a//y
print(f"{x}的{y}进制是:", end = '')
for i in list[::-1]:
if i==10:
print('A',end='')
elif i == 11:
print('B', end='')
elif i == 12:
print('C', end='')
elif i == 13:
print('D', end='')
elif i == 14:
print('E', end='')
elif i == 15:
print('F', end='')
else:
print(i,end='')

 

 

 

 

 

posted on 2022-04-25 22:05  橡皮小飒  阅读(8)  评论(2编辑  收藏  举报