import random print('用列表存储随机整数: ') lst = [random.randint(0, 100) for i in range(5)] print(lst) print('\n用集合存储随机整数: ') s1 = {random.randint(0, 100) for i in range(5)} print(s1) print('\n用集合存储随机整数: ') s2 = set() while len(s2) < 5: s2.add(random.randint(0, 100)) print(s2)
lst = [55, 92, 88, 79, 96] i = 0 while i < len(lst): print(lst[i], end=' ') i+=1 print() for i in range(len(lst)): print(lst[i], end = ' ') print() for i in lst: print(i , end = ' ')
print()
book_info = {'isbn': '978-7-5356-8297-0','书名': '白鲸记','作者': '克里斯多夫.夏布特','译者': '高文婧','出版社': '湖南美术出版社', '售价': 82} for key, value in book_info.items(): print(f'{key}: {value}') print() for item in book_info.items(): print(f'{item[0]}: {item[1]}') print() for value in book_info.values(): print(value, end = ' ') print() for key in book_info.keys(): print(book_info[key], end = ' ')
x='''The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!''' y=x.lower() z=[] d={} for i in y: if 'a'<= i <='z': z.append(i) for i in z: d[i]=d.get(i,0)+1 for i in range(26): if chr(97+i) not in d: d[chr(97+i)]=0 else: continue a=[(value,key) for key,value in d.items()] a=sorted(a,reverse=True) for i in a: print(f'{i[1]}:{i[0]}')
x='专业代号信息' print('{:-^20s}'.format(x)) d={'8326':'地信类','8329':'计算机类','8330':'气科类','8336':'防灾工程','8345':'海洋科学','8382':'气象工程'} for i in d: print(f'{i}:{d[i]}') x='学生专业查询' print('{:-^20s}'.format(x)) n=input('请输入学号:') if n!='#': while n!='#': x=n[4:8] if x not in d : print('不在这些专业中...') n=input('请输入学号:') else: print(f'专业是:{d[x]}') n=input('请输入学号:') print('查询结束') else: print('查询结束')
import random xO = random.randint(1,31) print('猜猜2023年5月哪一天是你的lucky day 标签:语句,%-,组合,数据类型,cart,products,10s,print,input From: https://www.cnblogs.com/lv1883405/p/17332468.html