实验三

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):
print(s2)

[1,100]，能

[0,5),不包括

(1,5),不包括

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

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(temperatures[0][2])
top=int(temperatures[0][3])
low_sum=0
top_sum=0
for i in range(len(temperatures)):
low_sum+=int(temperatures[i][2]


top_sum+=int(temperatures[i][3])
if int(temperatures[i][2])<low:
low=int(temperatures[i][2])
if int(temperatures[i][3])>top:
top=int(temperatures[i][3])
print('未来一周最低气温:',low,'℃')
print('未来一周最高气温: ',top,'℃')
print('未来一周平均气温区间: ',int(low_sum/7),'℃','~',int(top_sum/7),'℃')
import random
luck_day = random.randint(1,31)
print('猜猜2022年5月那一天会是你的lucky day:-)')
for i in range(3):
guess_day = eval(input('你有三次机会，猜吧（1~31）：'))
if guess_day == luck_day:
print('哇，猜中了:-)')
break
elif guess_day < luck_day:
print('猜早啦，你的lucky day还没到呢')
elif guess_day > luck_day:
print('猜晚啦，你的lucky day已经过啦')
else:
print(f'次数用光了，\n偷偷告诉你，5月你的lucky day是{luck_day}号.good lucky:-)')

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

posted @ 2022-04-27 12:30  杪秋有四0904  阅读(12)  评论(3编辑  收藏  举报