首页 > 编程语言 >实验3 控制语句和组合数据类型应用编程

实验3 控制语句和组合数据类型应用编程

时间:2023-04-22 15:46:41浏览次数:35  
标签:语句 count product 编程 数据类型 cart products print id

一、实验结论:

1、实验任务1:task1.py

程序源码:

 1 import random
 2 
 3 print('用列表存储随机整数: ')
 4 lst = [random.randint(0, 100) for i in range(5)]
 5 print(lst)
 6 
 7 print('\n用集合存储随机整数: ')
 8 s1 = {random.randint(0, 100) for i in range(5)}
 9 print(s1)
10 
11 print('\n用集合存储随机整数: ')
12 s2 = set()
13 while len(s2) < 5:
14     s2.add(random.randint(0, 100))
15 print(s2)

运行结果截图:

问题1: random.randint(0,100) 生成的随机整数范围是?能否取到100?  [0,100],能取到100。  

问题2:利用 list(range(5)) 生成的有序序列范围是?是否包括5?  [0,1,2,3,4],不包括5。

             利用 list(range(1,5)) 生成的有序序列范围是?是否包括5?  [1,2,3,4],不包括5。

问题3:使用line8代码生成的集合s1,len(s1)一定是5吗?如果不是,请解释原因。  len(s1)不一定是5,如果生成的随机数重复了,集合会去掉重复的随机数,len(s1)就会小于5。

问题4:使用line12-14生成的集合s2,len(s2)一定是5吗?如果不是,请解释原因。  len(s1)一定是5。

 

2、  实验任务2:task2_1.py

程序源码:

 1 # 列表遍历
 2 lst = [55, 92, 88, 79, 96]
 3 
 4 # 遍历方式1: 使用while + 索引
 5 i = 0
 6 while i < len(lst):
 7     print(lst[i], end = ' ')
 8     i += 1
 9 
10 print()
11 
12 # 遍历方式2:使用for + 索引
13 for i in range(len(lst)):
14     print(lst[i], end = ' ')
15 print()
16 
17 # 遍历方式3: 使用for...in
18 for i in lst:
19     print(i , end = ' ')
20 print()

运行结果截图:

task2_2.py

程序源码:

 1 # 字典遍历
 2 book_info = {'isbn': '978-7-5356-8297-0',
 3              '书名': '白鲸记',
 4              '作者': '克里斯多夫.夏布特',
 5              '译者': '高文婧',
 6              '出版社': '湖南美术出版社',
 7              '售价': 82
 8              }
 9 
10 # 遍历key-value对:实现方式1
11 for key, value in book_info.items():
12     print(f'{key}: {value}')
13 print()
14 
15 # 遍历key-value对:实现方式2
16 for item in book_info.items():
17     print(f'{item[0]}: {item[1]}')
18 print()
19 
20 # 遍历值:实现方式1
21 for value in book_info.values():
22     print(value, end=' ')
23 print()
24 
25 # 遍历值: 实现方式2
26 for key in book_info.keys():
27     print(book_info[key], end=' ')

运行结果截图:

task2_3.py

程序源码:

1 book_infos = [{'书名': '昨日的世界', '作者': '斯蒂芬.茨威格'},
2              {'书名': '局外人', '作者': '阿尔贝.加缪'},
3              {'书名': '设计中的设计', '作者': '原研哉'},
4              {'书名': '万历十五年', '作者': '黄仁宇'},
5              {'书名': '刀锋', '作者': '毛姆'}
6              ]
7 for i in range(len(book_infos)):
8     l=[v for v in book_infos[i].values()]
9     print(f'{i+1}.《{l[0]}》,{l[1]}')

运行结果截图:

 

3、实验任务3:task3.py

程序源码:

 1 text='''The Zen of Python, by Tim Peters
 2 
 3         Beautiful is better than ugly.
 4         Explicit is better than implicit.
 5         Simple is better than complex.
 6         Complex is better than complicated.
 7         Flat is better than nested.
 8         Sparse is better than dense.
 9         Readability counts.
10         Special cases aren't special enough to break the rules.
11         Although practicality beats purity.
12         Errors should never pass silently.
13         Unless explicitly silenced.
14         In the face of ambiguity, refuse the temptation to guess.
15         There should be one-- and preferably only one --obvious way to do it.
16         Although that way may not be obvious at first unless you're Dutch.
17         Now is better than never.
18         Although never is often better than *right* now.
19         If the implementation is hard to explain, it's a bad idea.
20         If the implementation is easy to explain, it may be a good idea.
21         Namespaces are one honking great idea -- let's do more of those!'''
22 
23 l=[text.lower().count(chr(i)) for i in range(97,97+26)]
24 d={}
25 for j in range(26):
26     d.update({chr(j+97):l[j]})
27 
28 l1=list(d.items())
29 l2=[(v,k) for k,v in l1]
30 for v,k in sorted(l2,reverse=True):
31     print(f'{k}:{v}')

运行结果截图:

 

4、实验任务4:task4.py

程序源码:

 1 code_majors={8326:'地信类',
 2              8329:'计算机类',
 3              8330:'气科类',
 4              8336:'防灾工程',
 5              8345:'海洋科学',
 6              8382:'气象工程'}
 7 
 8 print(f'{"专业代号信息":-^50s}')
 9 for k,v in code_majors.items():
10     print(f'{k}:{v}')
11 
12 print(f'{"学生专业查询":-^50s}')
13 n=input('请输入学号:')
14 while n!='#':
15     if int(n[4:8]) in code_majors:
16         print(f'专业是:{code_majors.get(int(n[4:8]))}')
17     else:
18         print('不在这些专业中...')
19     n=input('请输入学号:')
20 print('查询结束...')

运行结果截图:

 

5、实验任务5:task5.py

程序源码:

 1 import random
 2 lucky_day=random.randint(1,31)
 3 
 4 print(f'猜猜2023年5月哪一天会是你的lucky day{chr(0x1f609)}')
 5 d=eval(input('你有三次机会,猜吧(1~31):'))
 6 for i in range(3):
 7     if d<1 or d>31:
 8         print('地球上没有这一天啦,你是外星人吗')
 9     elif d<lucky_day:
10         print('猜早啦,你的lucky day还没到呢')
11     elif d>lucky_day:
12         print('猜晚啦,你的lucky day已经过啦')
13     else:
14         print(f'哇,猜中了{chr(0x1f923)}')
15         break
16     if i==2:
17         break
18     d=eval(input('再猜(1~31):'))
19 
20 if d!=lucky_day:
21     print('哇哦,次数用光啦.')
22     print(f'偷偷告诉你,5月你的lucky day是{lucky_day}号.good luck{chr(0x1f60a)}')

运行结果截图:

 

6、实验任务6:task6.py

程序源码:

 1 datas = {'2049777001': ['篮球', '羽毛球', '美食', '漫画'],
 2          '2049777002': ['音乐', '旅行'],
 3          '2049777003': ['马拉松', '健身', '游戏'],
 4          '2049777004': [],
 5          '2049777005': ['足球', '阅读'],
 6          '2049777006': ['发呆', '闲逛'],
 7          '2049777007': [],
 8          '2049777008': ['书法', '电影'],
 9          '2049777009': ['音乐', '阅读', '电影', '漫画'],
10          '2049777010': ['数学', '推理', '音乐', '旅行']
11          }
12 
13 l=[]
14 for v in datas.values():
15     l.extend(v)
16 s=set(l)
17 
18 d={}
19 for i in s:
20     d[i]=l.count(i)
21 
22 l1=list(d.items())
23 l2=[(v,k) for k,v in l1]
24 for v,k in sorted(l2,reverse=True):
25     print(f'{k}:{v}')

运行结果截图:

 

7、实验任务7:task7_1.py

程序源码:

 1 """
 2 家用电器销售系统
 3 v1.3
 4 """
 5 
 6 #欢迎信息
 7 print('欢迎使用家用电器销售系统!')
 8 
 9 #商品数据初始化
10 products=[
11         ['0001','电视机','海尔',5999.00,20],
12         ['0002','冰箱','西门子',6998.00,15],
13         ['0003','洗衣机','小天鹅',1999.00,10],
14         ['0004','空调','格力',3900.00,0],
15         ['0005','热水器','格力',688.00,30],
16         ['0006','笔记本','联想',5699.00,10],
17         ['0007','微波炉','苏泊尔',480.00,33],
18         ['0008','投影仪','松下',1250.00,12],
19         ['0009','吸尘器','飞利浦',999.00,9]
20         ]
21 
22 #初始化用户购物车
23 products_cart=[]
24 
25 option=input('请选择您的操作:1-查看商品;2-购物;3-查看购物车;其他-结账')
26 while option in['1','2','3']:
27     if option=='1':
28         #产品信息列表
29         print('产品和价格信息如下:')
30         print('**************************************************************')
31         print('%-10s'%'编号', '%-10s'%'名称',  '%-10s' %'品牌', '%-10s'%' 价格',
32         '%-10s'%'库存数量')
33         print('--------------------------------------------------------------')
34         for i in range(len(products)):
35             print('%-10s'%products[i][0],'%-10s'%products[i][1],'%-10s'%products[i][2],
36             '%10.2f'%products[i][3],'%10d'%products[i][4])
37         print('--------------------------------------------------------------')
38     elif option=='2':
39         product_id=input('请输入您要购买的产品编号:')
40         while product_id not in [item[0] for item in products]:
41             product_id=input('编号不存在,请重新输入您要购买的产品编号:')
42 
43         count=int(input('请输入您要购买的产品数量:'))
44         while count>products[int(product_id)-1][4]:
45             count=int(input('数量超出库存,请重新输入您要购买的产品数量:'))
46 
47         #将所购买商品加入购物车
48         if product_id not in [item[0] for item in products_cart]:
49             products_cart.append([product_id,count])
50         else:
51             for i in range(len(products_cart)):
52                 if products_cart[i][0]==product_id:
53                     products_cart[i][1]+=count
54 
55         #更新商品列表
56         for i in range(len(products)):
57             if products[i][0]==product_id:
58                 products[i][4]-=count
59     else:
60         print('购物车信息如下:')
61         print('******************************')
62         print('%-10s'%'编号','%-10s'%'购买数量')
63         print('------------------------------')
64         for i in range(len(products_cart)):
65             print('%-10s'%products_cart[i][0],'%6d'%products_cart[i][1])
66         print('------------------------------')
67     option=input('操作成功!请选择您的操作:1-查看商品;2-购物;3-查看购物车;其他-结账')
68 
69 #计算金额
70 if len(products_cart)>0:
71     amount=0
72     for i in range(len(products_cart)):
73         product_index=0
74         for j in range(len(products)):
75             if products[j][0]==products_cart[i][0]:
76                 product_index=j
77                 break
78         price=products[product_index][3]
79         count=products_cart[i][1]
80         amount+=price*count
81 
82     if 5000<amount<=10000:
83         amount=amount*0.95
84     elif 10000<amount<=20000:
85         amount=amount*0.90
86     elif amount>20000:
87         amount=amount*0.85
88     else:
89         amount=amount*1
90     print('购买成功,您需要支付%8.2f元'%amount)
91 
92 #退出系统
93 print('谢谢您的光临,下次再见!')

运行结果截图:

task7_2.py

程序源码:

 1 """
 2 家用电器销售系统
 3 v1.3
 4 """
 5 
 6 #欢迎信息
 7 print('欢迎使用家用电器销售系统!')
 8 
 9 #商品数据初始化
10 products=[
11         ['0001','电视机','海尔',5999.00,20],
12         ['0002','冰箱','西门子',6998.00,15],
13         ['0003','洗衣机','小天鹅',1999.00,10],
14         ['0004','空调','格力',3900.00,0],
15         ['0005','热水器','格力',688.00,30],
16         ['0006','笔记本','联想',5699.00,10],
17         ['0007','微波炉','苏泊尔',480.00,33],
18         ['0008','投影仪','松下',1250.00,12],
19         ['0009','吸尘器','飞利浦',999.00,9]
20         ]
21 
22 #初始化用户购物车
23 products_cart=[]
24 
25 option=input('请选择您的操作:1-查看商品;2-购物;3-查看购物车;其他-结账')
26 while option in['1','2','3']:
27     if option=='1':
28         #产品信息列表
29         print('产品和价格信息如下:')
30         print('**************************************************************')
31         print(f"{'编号':<10s}{'名称':<10s}{'品牌':<10s}{'价格':<10s}{'库存数量':<10s}")
32         print('--------------------------------------------------------------')
33         for i in range(len(products)):
34             print(f'{products[i][0]:<10s}{products[i][1]:<10s}{products[i][2]:<10s}{products[i][3]:<15.2f}{products[i][4]:<10d}')
35         print('--------------------------------------------------------------')
36     elif option=='2':
37         product_id=input('请输入您要购买的产品编号:')
38         while product_id not in [item[0] for item in products]:
39             product_id=input('编号不存在,请重新输入您要购买的产品编号:')
40 
41         count=int(input('请输入您要购买的产品数量:'))
42         while count>products[int(product_id)-1][4]:
43             count=int(input('数量超出库存,请重新输入您要购买的产品数量:'))
44 
45         #将所购买商品加入购物车
46         if product_id not in [item[0] for item in products_cart]:
47             products_cart.append([product_id,count])
48         else:
49             for i in range(len(products_cart)):
50                 if products_cart[i][0]==product_id:
51                     products_cart[i][1]+=count
52 
53         #更新商品列表
54         for i in range(len(products)):
55             if products[i][0]==product_id:
56                 products[i][4]-=count
57     else:
58         print('购物车信息如下:')
59         print('******************************')
60         print(f"{'编号':<10s}{'购买数量':<10s}")
61         print('------------------------------')
62         for i in range(len(products_cart)):
63             print(f'{products_cart[i][0]:<15s}{products_cart[i][1]:<6d}')
64         print('------------------------------')
65     option=input('操作成功!请选择您的操作:1-查看商品;2-购物;3-查看购物车;其他-结账')
66 
67 #计算金额
68 if len(products_cart)>0:
69     amount=0
70     for i in range(len(products_cart)):
71         product_index=0
72         for j in range(len(products)):
73             if products[j][0]==products_cart[i][0]:
74                 product_index=j
75                 break
76         price=products[product_index][3]
77         count=products_cart[i][1]
78         amount+=price*count
79 
80     if 5000<amount<=10000:
81         amount=amount*0.95
82     elif 10000<amount<=20000:
83         amount=amount*0.90
84     elif amount>20000:
85         amount=amount*0.85
86     else:
87         amount=amount*1
88     print(f'购买成功,您需要支付{amount:<8.2f}元')
89 
90 #退出系统
91 print('谢谢您的光临,下次再见!')

运行结果截图:

 

8、实验任务8:task8_1.py

程序源码:

 1 """
 2 家用电器销售系统
 3 v1.4
 4 """
 5 
 6 #欢迎信息
 7 print('欢迎使用家用电器销售系统!')
 8 
 9 #商品数据初始化
10 products=[
11         {'id':'0001','name':'电视机','brand':'海尔','price':5999.00,'count':20},
12         {'id':'0002','name':'冰箱','brand':'西门子','price':6998.00,'count':15},
13         {'id':'0003','name':'洗衣机','brand':'小天鹅','price':1999.00,'count':10},
14         {'id':'0004','name':'空调','brand':'格力','price':3900.00,'count':0},
15         {'id':'0005','name':'热水器','brand':'格力','price':688.00,'count':30},
16         {'id':'0006','name':'笔记本','brand':'联想','price':5699.00,'count':10},
17         {'id':'0007','name':'微波炉','brand':'苏泊尔','price':480.00,'count':33},
18         {'id':'0008','name':'投影仪','brand':'松下','price':1250.00,'count':12},
19         {'id':'0009','name':'吸尘器','brand':'飞利浦','price':999.00,'count':9},
20         ]
21 
22 #初始化用户购物车
23 products_cart=[]
24 
25 option=input('请选择您的操作:1-查看商品;2-购物;3-查看购物车;其他-结账')
26 while option in['1','2','3']:
27     if option=='1':
28         #产品信息列表
29         print('产品和价格信息如下:')
30         print('**************************************************************')
31         print('%-10s'%'编号', '%-10s'%'名称',  '%-10s' %'品牌', '%-10s'%' 价格',
32         '%-10s'%'库存数量')
33         print('--------------------------------------------------------------')
34         for i in range(len(products)):
35             print('%-10s'%products[i]['id'],'%-10s'%products[i]['name'],
36             '%-10s'%products[i]['brand'],'%10.2f'%products[i]['price'],
37             '%10d'%products[i]['count'])
38         print('--------------------------------------------------------------')
39     elif option=='2':
40         product_id=input('请输入您要购买的产品编号:')
41         while product_id not in [item['id'] for item in products]:
42             product_id=input('编号不存在,请重新输入您要购买的产品编号:')
43 
44         count=int(input('请输入您要购买的产品数量:'))
45         while count>products[int(product_id)-1]['count']:
46             count=int(input('数量超出库存,请重新输入您要购买的产品数量:'))
47 
48         #将所购买商品加入购物车
49         if product_id not in [item['id'] for item in products_cart]:
50             products_cart.append({'id':product_id,'count':count})
51         else:
52             for i in range(len(products_cart)):
53                 if products_cart[i].get('id')==product_id:
54                     products_cart[i]['count']+=count
55 
56         #更新商品列表
57         for i in range(len(products)):
58             if products[i]['id']==product_id:
59                 products[i]['count']-=count
60     else:
61         print('购物车信息如下:')
62         print('******************************')
63         print('%-10s'%'编号','%-10s'%'购买数量')
64         print('------------------------------')
65         for i in range(len(products_cart)):
66             print('%-10s'%products_cart[i]['id'],'%6d'%products_cart[i]['count'])
67         print('------------------------------')
68     option=input('操作成功!请选择您的操作:1-查看商品;2-购物;3-查看购物车;其他-结账')
69 
70 #计算金额
71 if len(products_cart)>0:
72     amount=0
73     for i in range(len(products_cart)):
74         product_index=0
75         for j in range(len(products)):
76             if products[j]['id']==products_cart[i]['id']:
77                 product_index=j
78                 break
79         price=products[product_index]['price']
80         count=products_cart[i]['count']
81         amount+=price*count
82 
83     if 5000<amount<=10000:
84         amount=amount*0.95
85     elif 10000<amount<=20000:
86         amount=amount*0.90
87     elif amount>20000:
88         amount=amount*0.85
89     else:
90         amount=amount*1
91     print('购买成功,您需要支付%8.2f元'%amount)
92 
93 #退出系统
94 print('谢谢您的光临,下次再见!')

运行结果截图:

task8_2.py

程序源码:

 1 """
 2 家用电器销售系统
 3 v1.4
 4 """
 5 
 6 #欢迎信息
 7 print('欢迎使用家用电器销售系统!')
 8 
 9 #商品数据初始化
10 products=[
11         {'id':'0001','name':'电视机','brand':'海尔','price':5999.00,'count':20},
12         {'id':'0002','name':'冰箱','brand':'西门子','price':6998.00,'count':15},
13         {'id':'0003','name':'洗衣机','brand':'小天鹅','price':1999.00,'count':10},
14         {'id':'0004','name':'空调','brand':'格力','price':3900.00,'count':0},
15         {'id':'0005','name':'热水器','brand':'格力','price':688.00,'count':30},
16         {'id':'0006','name':'笔记本','brand':'联想','price':5699.00,'count':10},
17         {'id':'0007','name':'微波炉','brand':'苏泊尔','price':480.00,'count':33},
18         {'id':'0008','name':'投影仪','brand':'松下','price':1250.00,'count':12},
19         {'id':'0009','name':'吸尘器','brand':'飞利浦','price':999.00,'count':9},
20         ]
21 
22 #初始化用户购物车
23 products_cart=[]
24 
25 option=input('请选择您的操作:1-查看商品;2-购物;3-查看购物车;其他-结账')
26 while option in['1','2','3']:
27     if option=='1':
28         #产品信息列表
29         print('产品和价格信息如下:')
30         print('**************************************************************')
31         print(f"{'编号':<10s}{'名称':<10s}{'品牌':<10s}{'价格':<10s}{'库存数量':<10s}")
32         print('--------------------------------------------------------------')
33         for i in range(len(products)):
34             print(f"{products[i]['id']:<10s}{products[i]['name']:<10s}{products[i]['brand']:<10s}{products[i]['price']:<15.2f}{products[i]['count']:<10d}")
35         print('--------------------------------------------------------------')
36     elif option=='2':
37         product_id=input('请输入您要购买的产品编号:')
38         while product_id not in [item['id'] for item in products]:
39             product_id=input('编号不存在,请重新输入您要购买的产品编号:')
40 
41         count=int(input('请输入您要购买的产品数量:'))
42         while count>products[int(product_id)-1]['count']:
43             count=int(input('数量超出库存,请重新输入您要购买的产品数量:'))
44 
45         #将所购买商品加入购物车
46         if product_id not in [item['id'] for item in products_cart]:
47             products_cart.append({'id':product_id,'count':count})
48         else:
49             for i in range(len(products_cart)):
50                 if products_cart[i].get('id')==product_id:
51                     products_cart[i]['count']+=count
52 
53         #更新商品列表
54         for i in range(len(products)):
55             if products[i]['id']==product_id:
56                 products[i]['count']-=count
57     else:
58         print('购物车信息如下:')
59         print('******************************')
60         print(f"{'编号':<15s}{'购买数量':<6s}")
61         print('------------------------------')
62         for i in range(len(products_cart)):
63             print(f"{products_cart[i]['id']:<10s}{products_cart[i]['count']:<6d}")
64         print('------------------------------')
65     option=input('操作成功!请选择您的操作:1-查看商品;2-购物;3-查看购物车;其他-结账')
66 
67 #计算金额
68 if len(products_cart)>0:
69     amount=0
70     for i in range(len(products_cart)):
71         product_index=0
72         for j in range(len(products)):
73             if products[j]['id']==products_cart[i]['id']:
74                 product_index=j
75                 break
76         price=products[product_index]['price']
77         count=products_cart[i]['count']
78         amount+=price*count
79 
80     if 5000<amount<=10000:
81         amount=amount*0.95
82     elif 10000<amount<=20000:
83         amount=amount*0.90
84     elif amount>20000:
85         amount=amount*0.85
86     else:
87         amount=amount*1
88     print(f'购买成功,您需要支付{amount:<8.2f}元')
89 
90 #退出系统
91 print('谢谢您的光临,下次再见!')

运行结果截图:

 

二、实验总结:

1. 知道Python中组合数据类型字符串(str)、列表(list)、元组(tuple)、集合(set)、字典(dict)的表示、特性。 2. 能够正确使用字符串(str)、列表(list)、元组(tuple)、集合(set)、字典(dict)的常用操作。 3. 针对具体问题场景,灵活、组合使用多种数据类型,应用或设计算法,使用控制语句编程解决实际问题。  

标签:语句,count,product,编程,数据类型,cart,products,print,id
From: https://www.cnblogs.com/myf-/p/17332784.html

相关文章

  • Rust编程语言入门之模式匹配
    模式匹配模式模式是Rust中的一种特殊语法,用于匹配复杂和简单类型的结构将模式与匹配表达式和其他构造结合使用,可以更好地控制程序的控制流模式由以下元素(的一些组合)组成:字面值解构的数组、enum、struct和tuple变量通配符占位符想要使用模式,需要将其与某个值进行比......
  • 简单学懂链式编程
    简单学懂链式编程一句话定义链式编程是一种编程风格,它允许在同一个对象上通过多个方法的调用链实现一系列操作,从而简化代码,提高可读性,和代码的可维护性。一个流程看懂创建对象->连续调用对象方法->返回对象本身->使用对象方法获取属性或执行其他操作。示例publicclas......
  • 实验3 控制语句与组合数据类型应用编程
    实验任务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用集合存储随机整数:')s2......
  • C语言和C++的switch语句用法
    C语言和C++的switch语句用法是相似的,但在一些细节上有所不同。在C语言中,switch语句的用法如下:switch(expression){  caseconstant1:    //dosomething    break;  caseconstant2:    //dosomething    break;  //...  ......
  • lua变量、数据类型、if判断条件和数据结构table以及【lua 函数】
    一、lua变量【全局变量和局部变量和表中的域】Lua变量有三种类型:全局变量和局部变量和表中的域。▪全局变量:默认情况下,Lua中所有的变量都是全局变量。▪局部变量:使用local显式声明在函数内的变量,以及函数的参数,都是局部变量。在函数外即使用local去声明,它的作用域也是当前的整......
  • C ++各个数据类型的输入输出
    C++中各个数据类型的输入输出主要使用iostream库和格式化输入输出函数printf、scanf等,下面是各个数据类型的输入输出方式:1.整型:使用cin和cout进行输入输出,或者使用scanf和printf进行输入输出。intn;cin>>n;cout<<n<<endl;scanf("%d",&n);printf("%d\n",n);2.浮点型:使......
  • 试验任务3 控制语句与组合数据类型应用编程
    1.试验任务11importrandom23print('用列表存储随机整数:')4lst=[random.randint(0,100)foriinrange(5)]5print(lst)67print('\n拥集合存储随机整数:')8s1={random.randint(0,100)foriinrange(5)}9print(s1)1011print('\n用集......
  • 04-目录---Linux编程
    第01章:Linux常用命令vim的使用:链接vimrc:链接shell命令行操作:链接hitory历史命令:链接安装较新vim:链接安装plug-vim:链接安装更新的cmake:链接安装更新的gcc:链接安装python3.8:链接第02章:Linux编译调试基础makefile:链接gdb调试:链接库的制作:链接第03章:标准IOfopen与fclos......
  • C 语言各个数据类型的输入输出
    -1.整型(int)的输入输出: 输入: ```cintnum;printf("请输入一个整数:\n");scanf("%d",&num);//注意取地址符&``` 输出: ```cintnum=123;printf("这个数字是%d。\n",num);``` 2.浮点型(float和double)的输入输出: 输入: ```cfloatnum1;doubl......
  • 加密与解密x64逆向——变量、if和switch、循环语句
    数据结构主要是对局部变量,全局变量,数组等的识别。1.局部变量局部变量是函数内定义的变量,存放的内存区域称之为栈区。生命周期就是从函数进入到返回释放。函数在入口处申请了预留栈空间和局部变量空间,也就是subrsp,30h。局部变量空间在高地址。在应用程序被编译成release版本......