任务一
实验源码
运行结果截图
任务二
实验源码
1 lst = [55,92,88,79,96] 2 3 i = 0 4 while i < len(lst): 5 print(lst[i],end = '') 6 i += 1 7 print() 8 9 for i in range(len(lst)): 10 print(lst[i],end ='') 11 print() 12 13 for i in lst: 14 print(i,end = '') 15 print()task1
运行结果截图
实验源码
1 book_info = {'isbn': '978-7-5356-8297-0', 2 '书名': '白鲸记', 3 '作者': '克里斯多夫.夏布特', 4 '译者': '高文婧', 5 '出版社': '湖南美术出版社', 6 '售价':82} 7 for key ,value in book_info.items(): 8 print(f'{key}: {value}') 9 print() 10 11 for item in book_info.items(): 12 print(f'{item[0]}: {item[1]}') 13 print() 14 15 for value in book_info.values(): 16 print(value, end = ' ') 17 print() 18 19 for key in book_info.keys(): 20 print(book_info[key], end = ' ')task2
运行结果截图
实验源码
1 book_infos = [{'书名': '昨日的世界', '作者': '斯蒂芬.茨威格'}, 2 {'书名': '局外人', '作者': '阿尔贝.加缪'}, 3 {'书名': '设计中的设计', '作者': '原研哉'}, 4 {'书名': '万历十五年', '作者': '黄仁宇'}, 5 {'书名': '刀锋', '作者': '毛姆'} 6 ] 7 8 9 i = 0 10 while i < len(book_infos): 11 j = book_infos[i] 12 b = str(j['书名']) 13 j['书名'] = b.join('《》') 14 print(str(i+1)+'.'+j['书名']+','+j['作者']) 15 i += 1task3
运行结果截图
任务三
实验源码
1 text1=''' 2 The Zen of Python, by Tim Peters 3 4 Beautiful is better than ugly. 5 Explicit is better than implicit. 6 Simple is better than complex. 7 Complex is better than complicated. 8 Flat is better than nested. 9 Sparse is better than dense. 10 Readability counts. 11 Special cases aren't special enough to break the rules. 12 Although practicality beats purity. 13 Errors should never pass silently. 14 Unless explicitly silenced. 15 In the face of ambiguity, refuse the temptation to guess. 16 There should be one-- and preferably only one --obvious way to do it. 17 Although that way may not be obvious at first unless you're Dutch. 18 Now is better than never. 19 Although never is often better than *right* now. 20 If the implementation is hard to explain, it's a bad idea. 21 If the implementation is easy to explain, it may be a good idea. 22 Namespaces are one honking great idea -- let's do more of those! 23 ''' 24 text=text1.lower() 25 26 lst=[text.count(chr(i)) for i in range(97,97+26)] 27 d={} 28 for i in range(26): 29 d.update({chr(i+97):lst[i]}) 30 31 lst1=list(d.items()) 32 lst2=[(i,j) for j,i in lst1] 33 for i,j in sorted(lst2,reverse=True): 34 print(f'{j}:{i}')task
运行结果截图
任务四
实验源码
1 code_majors={8326:'地信类', 2 8329:'计算机类', 3 8330:'气科类', 4 8336:'防灾工程', 5 8345:'海洋科学', 6 8382:'气象工程'} 7 8 print('专业代号信息'.center(50, '-')) 9 for key,value in code_majors.items(): 10 print(f'{key}:{value}') 11 12 print('学生专业查询'.center(50, '-')) 13 code=list(code_majors.keys()) 14 number = input('请输入学号:') 15 while number !='#': 16 number_code = int(number[4:8]) 17 if code_majors.get(number_code)==None: 18 print('不在这些专业中...') 19 else: 20 major=code_majors.get(number_code) 21 print('专业是:'+major) 22 number = input('请输入学号:') 23 24 print('查询结束...')task
运行结果截图
任务五
实验源码
1 import random 2 xO = random.randint(1,31) 3 print('猜猜2023年5月哪一天是你的lucky day 标签:count,product,cart,products,print,实验,id From: https://www.cnblogs.com/sqdl666/p/17332768.html