首页 > 其他分享 >实验三

实验三

时间:2023-04-25 20:11:07浏览次数:32  
标签:count product cart products print 实验 id

任务一

实验源码

运行结果截图

任务二

实验源码

 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 += 1
task3

运行结果截图

任务三

实验源码

 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

相关文章

  • 实验3 控制语句与组合数据类型应用编程
    实验任务1实验源码1importrandom23print('用列表存储随机整数:')4lst=[random.randint(0,100)foriinrange(5)]5print(lst)67print('\n用集合存储随机整数:')8s1={random.randint(0,100)foriinrange(5)}9print(s1)1011print('......
  • 实验3
    1.实验任务1task1.py实验代码:importrandomprint('用列表储存随机整数:')lst=[random.randint(0,100)foriinrange(5)]print(lst)print('\n用集合储存随机整数:')s1={random.randint(0,100)foriinrange(5)}print(s1)print('\n用集合储存随机整数:')s......
  • 实验3
    实验任务1:源码:importrandomprint('用列表存储随机整数:')lst=[random.randint(0,100)foriinrange(5)]print(lst)print('\n用集合存储随机整数:')s1={random.randint(0,100)foriinrange(5)}print(s1)print('\n用集合存储随机整数:')s2=set(......
  • 实验三
    实验任务一:实验源码:1importrandom23print('用列表存储随机整数:')4lst=[random.randint(0,100)foriinrange(5)]5print(lst)67print('\n用集合存储随机整数:')8s1={random.randint(0,100)foriinrange(5)}9print(s1)1011print('\......
  • 实验三
    task1源代码importrandomprint('用列表存储随机整数:')lst=[random.randint(0,100)foriinrange(5)]print(lst)print('\n用集合存储随机整数:')s1={random.randint(0,100)foriinrange(5)}print(s1)print('\n用集合存储随机整数:')s2=set()whilelen(......
  • 实验3 控制语句与组合数据类型应用编程
    一.实验目的:1.知道Python中组合数据类型字符串(str)、列表(list)、元组(tuple)、集合(set)、字典的表示、特性2.能够正确、熟练使用字符串(str)、列表(list)、元组(tuple)、集合(set)、字典的常用操作3.针对具体问题场景,能够灵活、组合使用多种数据类型,应用或设计算法,使用......
  • 实验3
    实验任务1源代码:importrandomprint('用列表存储随机整数:')lst=[random.randint(0,100)foriinrange(5)]print(lst)print('\n用集合存储随机整数:')s1={random.randint(0,100)foriinrange(5)}print(s1)print('\n用集合存储随机整数:')s2=set()whil......
  • linux操作系统分析实验五-深入理解进程切换
    Lab5:深入理解进程切换首先找到对应进程调度的代码文件Kernal/sched/core.c  找到context_switch()函数   其中包括rq,为进程的runningqueue;以及进程切换前后的进程描述符prev和next  首先调用一些函数做上下文切换的准备,与最后出现的finish_task_switch()成......
  • 实验3 控制语句和组合数据类型应用编程
    task1.py1importrandom2print('用列表存储随机整数:')3lst=[random.randint(0,100)foriinrange(5)]4print(lst)5print('\n用集合存储随机整数:')6s1={random.randint(0,100)foriinrange(5)}7print(s1)8print('\n用集合存储随机整数......
  • 实验三
    task1importrandomprint('用列表存储随机整数:')lst=[random.randint(0,100)foriinrange(5)]print(lst)print('\n用集合存储随机整数:')s1={random.randint(0,100)foriinrange(5)}print(s1)print('\n用集合存储随机整数:')s2=set()while......