1 import random
 2 print('用列表存储随机整数: ')
 3 ls = [random.randint(1, 100) for i in range(5)]
 4 print(ls)
 5 print('\n用集合存储随机整数: ')
 6 s1 = {random.randint(1,100) for i in range(5)}
 7 print(s1)
 8 print('\n用集合存储随机整数: ')
 9 s2 = set()
10 while(len(s2)<5):
11     s2.add(random.randint(1,100))
12 print(s2)

 问题1:1-99,不能

问题2:0-4,否

             1-4,否

问题3:不一定

问题4:一定

 1 datas = {'2049777001': ['篮球', '羽毛球', '美食', '漫画'],
 2 '2049777002': ['音乐', '旅行'],
 3 '2049777003': ['马拉松', '健身', '游戏'],
 4 '2049777004': [],
 5 '2049777005': ['足球', '阅读'],
 6 '2049777006': ['发呆', '闲逛'],
 7 '2049777007': [],
 8 '2049777008': ['书法', '电影'],
 9 '2049777009': ['音乐', '阅读', '电影', '漫画'],
10 '2049777010': ['数学', '推理', '音乐', '旅行']}
11 v={}
12 for i in datas.values():
13     for j in i:
14         v[j]=v.get(j,0)+1
15 x=list(v.keys())
16 y=list(v.values())
17 z=[(y[i],x[i] ) for i in range(len(x))]
18 for j in sorted(z,reverse=True):
19     print(f"{j[1]}:{j[0]}")

 1 import math
 2 temperatures= [['2022-04-18', '星期一', '10', '22'],
 3 ['2022-04-19', '星期二', '10', '22'],
 4 ['2022-04-20', '星期三', '12', '25'],
 5 ['2022-04-21', '星期四', '13', '28'],
 6 ['2022-04-22', '星期五', '16', '31'],
 7 ['2022-04-23', '星期六', '19', '31'],
 8 ['2022-04-24', '星期日', '19', '27']]
 9 min_tp=[]
10 max_tp=[]
11 for i in temperatures:
12     min_tp.append(eval(i[2]))
13     max_tp.append(eval(i[3]))
14 min_tp.sort()
15 max_tp.sort(reverse=True)
16 print("未来一周最高气温:{}℃".format(max_tp[0]))
17 print("未来一周最低气温:{}℃".format(min_tp[0]))
18 avg1 =round(sum(min_tp)/ len(min_tp),0)
19 print('平均最低气温是:{}'.format(avg1))
20 avg2 =round(sum(max_tp)/ len(max_tp),0)
21 print('平均最高气温是:{}'.format(avg2))
22 print("未来一周的平均气温区间是",avg1,"℃~",avg2,"")

 1 print("猜猜2020年哪一天会是你的lucky day:-")
 2 import random
 3 lucky_day=random.randint(1,31)
 4 x=int(lucky_day)
 5 x1=int(input("你有三次机会,猜吧(1~31):"))
 6 if x1==x:
 7     print("哇,猜中了")
 8 elif x1<x:
 9     print("猜早啦,你的lucky day还没到呢")
10     x2=int(input("再猜(1~31):"))
11     if x2==x:
12         print("哇,猜中了")
13     elif x2<x:
14         print("猜早啦,你的lucky day还没到呢")
15         x3=int(input("再猜(1~31):"))
16         if x3==x:
17             print("哇,猜中了")
18         elif x3<x:
19             print("猜早啦,你的lucky day还没到呢")
20             print("次数用光啦")
21             print("偷偷告诉你,5月你的lucky day是",x,"号.good lucky:-")
22         elif x3>x:
23             print("猜晚啦,你的lucky day已经过了")
24             print("次数用光啦")
25             print("偷偷告诉你,5月你的lucky day是",x,"号.good lucky:-")
26     elif x2>x:
27         print("猜晚啦,你的lucky day已经过了")
28         x3=int(input("再猜(1~31):"))
29         if x3==x:
30             print("哇,猜中了")
31         elif x3<x:
32             print("猜早啦,你的lucky day还没到呢")
33             print("次数用光啦")
34             print("偷偷告诉你,5月你的lucky day是",x,"号.good lucky:-")
35         elif x3>x:
36             print("猜晚啦,你的lucky day已经过了")
37             print("次数用光啦")
38             print("偷偷告诉你,5月你的lucky day是",x,"号.good lucky:-")
39 elif x1>x:
40     print("猜晚啦,你的lucky day已经过了")
41     x2=int(input("再猜(1~31):"))
42     if x2==x:
43         print("哇,猜中了")
44     elif x2<x:
45         print("猜早啦,你的lucky day还没到呢")
46         x3=int(input("再猜(1~31):"))
47         if x3==x:
48             print("哇,猜中了")
49         elif x3<x:
50             print("猜早啦,你的lucky day还没到呢")
51             print("次数用光啦")
52             print("偷偷告诉你,5月你的lucky day是",x,"号.good lucky:-")
53         elif x3>x:
54             print("猜晚啦,你的lucky day已经过了")
55             print("次数用光啦")
56             print("偷偷告诉你,5月你的lucky day是",x,"号.good lucky:-")
57     elif x2>x:
58         print("猜晚啦,你的lucky day已经过了")
59         x3=int(input("再猜(1~31):"))
60         if x3==x:
61             print("哇,猜中了")
62         elif x3<x:
63             print("猜早啦,你的lucky day还没到呢")
64             print("次数用光啦")
65             print("偷偷告诉你,5月你的lucky day是",x,"号.good lucky:-")
66         elif x3>x:
67             print("猜晚啦,你的lucky day已经过了")
68             print("次数用光啦")
69             print("偷偷告诉你,5月你的lucky day是",x,"号.good lucky:-")

 1 def f(n, x):
 2     a=[0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F']
 3     b=[]
 4     while True:
 5         s=n // x
 6         y=n % x
 7         b=b+[y]
 8         if s==0:
 9             break
10         n=s
11     b.reverse()
12     ans = ''
13     for i in b:
14         ans += str(a[i])
15     return ans
16 A,B = map(int, input().split())
17 #A是转化前进制,B是转化后进制
18 n = int(input())
19 n = int(str(n), A)
20 ans = f(n, B)
21 print(n,"",B,"进制数是:",ans)

 

posted on 2022-04-25 17:13  starry。  阅读(13)  评论(2编辑  收藏  举报