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': ['数学', '推理', '音乐', '旅行']} a = list(datas.values()) b = [] for i in a: for m in i: b.append(m) n = {} for k in b: n[k] = b.count(k) list1 = list(n.items()) list2 = [(b, a) for a, b in list1] for x, y in reversed(sorted(list2)): print(f'{y}:{x}')
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(i[2]) b.append(i[3]) print('最低温度',min(a),'℃') print('最高温度',max(b),'℃') c=0 for q in a: c=c+int(q) v=c/len(a) d=0 for t in b: d=d+int(t) w=d/len(b) print('平均温度区间','%.f'%v,'℃','~','%.f'%w,'℃')
import random x = random.randint(1,31) print('猜一下幸运日期吧') q=0 i=0 while i==0: a=eval(input('就三次机会,猜吧:')) if q<2: if a==x: print('猜对了') break elif a<x: print('早了') q+=1 continue elif a>x: print('晚了') q+=1 continue elif q>=2: print('哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈,没机会了','是',x,'号') break
x = int(input('x:')) n = int(input('n:')) q=[] i=0 while i==0: if x//n==0: break else: t=x%n x=x//n q.append(t) continue for b in range(len(q)): p=str(q[b]) print(''.join(p),end="")