实验三
作者:互联网
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': ['数学', '推理', '音乐', '旅行']} 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 l=random.randint(1,31) print("猜猜2022年5月哪一天会是你的lucky day:-)") a=int(input("你有三次机会,猜吧(1~31):")) if a==l: print("哇,猜中啦:-)") else: if a<l: print("猜早啦,你的lucky day还没到呢") if a>l: print("猜晚啦,你的lucky day已经过啦") f=0 while(f<2): b=int(input("再猜(1~31):")) if b==l: print("哇,猜中啦:-)") f=300 else: if b>l: print("猜晚啦,你的lucky day已经过啦") f+=1 if b<l: print("猜早啦,你的lucky day还没到呢") f+=1 if f==2: print("次数用光啦") print("偷偷告诉你,5月你的lucky day是{}号.good luck:-)".format(l))
s=input('输入十进制整数x和要转换的进制n(2或8或16):') t=['A','B','C','D','E','F'] for i in range(len(s)): if s[i]==',': k=i break ans='' x=int(s[0:i]) n=int(s[i+1:]) m=x while x//n!=0: if x%n<10: ans=str(x%n)+ans else: i=x%n-10 ans=t[i]+ans x=x//n ans=str(x)+ans print(f'{m}的{n}进制是:{ans}')
标签:04,int,top,实验,temperatures,2022,print 来源: https://www.cnblogs.com/dyx8/p/16196615.html