bai-python-hwc 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bai_python_hwc/__init__.py +46 -0
- bai_python_hwc/answers/hwc101.py +38 -0
- bai_python_hwc/answers/hwc103.py +52 -0
- bai_python_hwc/answers/hwc104.py +45 -0
- bai_python_hwc/answers/hwc105.py +45 -0
- bai_python_hwc/answers/hwc106.py +56 -0
- bai_python_hwc/answers/hwc107.py +49 -0
- bai_python_hwc/answers/hwc108.py +45 -0
- bai_python_hwc/answers/hwc109.py +50 -0
- bai_python_hwc/answers/hwc110.py +42 -0
- bai_python_hwc/answers/hwc111.py +47 -0
- bai_python_hwc/answers/hwc112.py +42 -0
- bai_python_hwc/answers/hwc113.py +58 -0
- bai_python_hwc/answers/hwc114.py +58 -0
- bai_python_hwc/answers/hwc115.py +38 -0
- bai_python_hwc/answers/hwc116.py +44 -0
- bai_python_hwc/answers/hwc117.py +46 -0
- bai_python_hwc/answers/hwc118.py +47 -0
- bai_python_hwc/answers/hwc119.py +44 -0
- bai_python_hwc/answers/hwc120.py +41 -0
- bai_python_hwc/answers/hwc121.py +50 -0
- bai_python_hwc/answers/hwc122.py +54 -0
- bai_python_hwc/answers/hwc123.py +43 -0
- bai_python_hwc/answers/hwc124.py +41 -0
- bai_python_hwc/answers/hwc125.py +52 -0
- bai_python_hwc/answers/hwc126.py +40 -0
- bai_python_hwc/answers/hwc127.py +41 -0
- bai_python_hwc/answers/hwc128.py +39 -0
- bai_python_hwc/answers/hwc130.py +46 -0
- bai_python_hwc/answers/hwc131.py +46 -0
- bai_python_hwc/answers/hwc132.py +38 -0
- bai_python_hwc/answers/hwc133.py +61 -0
- bai_python_hwc/answers/hwc134.py +45 -0
- bai_python_hwc/answers/hwc135.py +49 -0
- bai_python_hwc/answers/hwc136.py +43 -0
- bai_python_hwc/answers/hwc201.py +47 -0
- bai_python_hwc/answers/hwc202.py +47 -0
- bai_python_hwc/answers/hwc203.py +48 -0
- bai_python_hwc/answers/hwc204.py +61 -0
- bai_python_hwc/answers/hwc205.py +56 -0
- bai_python_hwc/answers/hwc206.py +53 -0
- bai_python_hwc/answers/hwc207.py +43 -0
- bai_python_hwc/answers/hwc208.py +57 -0
- bai_python_hwc/answers/hwc209.py +42 -0
- bai_python_hwc/answers/hwc210.py +46 -0
- bai_python_hwc/answers/hwc211.py +62 -0
- bai_python_hwc/answers/hwc212.py +58 -0
- bai_python_hwc/answers/hwc213.py +54 -0
- bai_python_hwc/answers/hwc214.py +55 -0
- bai_python_hwc/answers/hwc215.py +53 -0
- bai_python_hwc/answers/hwc216.py +50 -0
- bai_python_hwc/answers/hwc217.py +38 -0
- bai_python_hwc/answers/hwc218.py +44 -0
- bai_python_hwc/answers/hwc219.py +49 -0
- bai_python_hwc/answers/hwc220.py +58 -0
- bai_python_hwc/answers/hwc221.py +49 -0
- bai_python_hwc/answers/hwc222.py +48 -0
- bai_python_hwc/answers/hwc223.py +39 -0
- bai_python_hwc/answers/hwc224.py +47 -0
- bai_python_hwc/answers/hwc225.py +50 -0
- bai_python_hwc/answers/hwc226.py +41 -0
- bai_python_hwc/answers/hwc227.py +40 -0
- bai_python_hwc/answers/hwc228.py +41 -0
- bai_python_hwc/answers/hwc229.py +51 -0
- bai_python_hwc/answers/hwc230.py +41 -0
- bai_python_hwc/answers/hwc231.py +39 -0
- bai_python_hwc/answers/hwc232.py +44 -0
- bai_python_hwc/answers/hwc233.py +49 -0
- bai_python_hwc/answers/hwc234.py +52 -0
- bai_python_hwc/answers/hwc235.py +45 -0
- bai_python_hwc/answers/hwc236.py +53 -0
- bai_python_hwc/answers/hwc237.py +56 -0
- bai_python_hwc/answers/hwc238.py +52 -0
- bai_python_hwc/answers/hwc239.py +60 -0
- bai_python_hwc/answers/hwc240.py +45 -0
- bai_python_hwc/answers/hwc241.py +48 -0
- bai_python_hwc/answers/hwc242.py +50 -0
- bai_python_hwc/answers/hwc243.py +61 -0
- bai_python_hwc/answers/hwc244.py +61 -0
- bai_python_hwc/answers/hwc245.py +47 -0
- bai_python_hwc/answers/hwc246.py +52 -0
- bai_python_hwc/answers/hwc247.py +76 -0
- bai_python_hwc/answers/hwc301.py +44 -0
- bai_python_hwc/answers/hwc302.py +53 -0
- bai_python_hwc/answers/hwc303.py +63 -0
- bai_python_hwc/answers/hwc304.py +56 -0
- bai_python_hwc/answers/hwc305.py +59 -0
- bai_python_hwc/answers/hwc306.py +60 -0
- bai_python_hwc/answers/hwc307.py +50 -0
- bai_python_hwc/answers/hwc308.py +59 -0
- bai_python_hwc/answers/hwc309.py +48 -0
- bai_python_hwc/answers/hwc310.py +38 -0
- bai_python_hwc/answers/hwc311.py +48 -0
- bai_python_hwc/answers/hwc312.py +49 -0
- bai_python_hwc/answers/hwc313.py +54 -0
- bai_python_hwc/answers/hwc314.py +49 -0
- bai_python_hwc/answers/hwc315.py +63 -0
- bai_python_hwc/answers/hwc316.py +65 -0
- bai_python_hwc/answers/hwc317.py +57 -0
- bai_python_hwc/answers/hwc318.py +55 -0
- bai_python_hwc/answers/hwc319.py +50 -0
- bai_python_hwc/answers/hwc320.py +84 -0
- bai_python_hwc/answers/hwc321.py +49 -0
- bai_python_hwc/answers/hwc322.py +49 -0
- bai_python_hwc/answers/hwc323.py +69 -0
- bai_python_hwc/answers/hwc324.py +66 -0
- bai_python_hwc/answers/hwc325.py +49 -0
- bai_python_hwc/answers/hwc326.py +53 -0
- bai_python_hwc/answers/hwc327.py +38 -0
- bai_python_hwc/answers/hwc328.py +50 -0
- bai_python_hwc/answers/hwc329.py +59 -0
- bai_python_hwc/answers/hwc330.py +45 -0
- bai_python_hwc/answers/hwc332.py +57 -0
- bai_python_hwc/answers/hwc401.py +50 -0
- bai_python_hwc/answers/hwc402.py +43 -0
- bai_python_hwc/answers/hwc403.py +73 -0
- bai_python_hwc/answers/hwc404.py +51 -0
- bai_python_hwc/answers/hwc405.py +62 -0
- bai_python_hwc/answers/hwc406.py +66 -0
- bai_python_hwc/answers/hwc407.py +49 -0
- bai_python_hwc/answers/hwc408.py +67 -0
- bai_python_hwc/answers/hwc409.py +51 -0
- bai_python_hwc/answers/hwc410.py +52 -0
- bai_python_hwc/answers/hwc411.py +57 -0
- bai_python_hwc/answers/hwc412.py +53 -0
- bai_python_hwc/answers/hwc413.py +65 -0
- bai_python_hwc/answers/hwc414.py +50 -0
- bai_python_hwc/answers/hwc415.py +61 -0
- bai_python_hwc/answers/hwc416.py +69 -0
- bai_python_hwc/answers/hwc418.py +47 -0
- bai_python_hwc/answers/hwc419.py +62 -0
- bai_python_hwc/answers/hwc421.py +51 -0
- bai_python_hwc/answers/hwc424.py +48 -0
- bai_python_hwc/answers/hwc501.py +63 -0
- bai_python_hwc/answers/hwc502.py +69 -0
- bai_python_hwc/answers/hwc503.py +75 -0
- bai_python_hwc/answers/hwc504.py +52 -0
- bai_python_hwc/answers/hwc505.py +63 -0
- bai_python_hwc/answers/hwc506.py +61 -0
- bai_python_hwc/answers/hwc508.py +60 -0
- bai_python_hwc/answers/hwc509.py +85 -0
- bai_python_hwc/answers/hwc510.py +56 -0
- bai_python_hwc/answers/hwc511.py +52 -0
- bai_python_hwc/answers/hwc513.py +63 -0
- bai_python_hwc/answers/hwc514.py +74 -0
- bai_python_hwc/answers/hwc515.py +83 -0
- bai_python_hwc/answers/hwc516.py +67 -0
- bai_python_hwc/answers/hwc517.py +46 -0
- bai_python_hwc/answers/hwc520.py +54 -0
- bai_python_hwc/answers/hwc526.py +58 -0
- bai_python_hwc/attachments/hwc424.pdf +0 -0
- bai_python_hwc/attachments/hwc501.pdf +0 -0
- bai_python_hwc/questions/hwc101.txt +17 -0
- bai_python_hwc/questions/hwc103.txt +27 -0
- bai_python_hwc/questions/hwc104.txt +22 -0
- bai_python_hwc/questions/hwc105.txt +23 -0
- bai_python_hwc/questions/hwc106.txt +26 -0
- bai_python_hwc/questions/hwc107.txt +29 -0
- bai_python_hwc/questions/hwc108.txt +18 -0
- bai_python_hwc/questions/hwc109.txt +24 -0
- bai_python_hwc/questions/hwc110.txt +16 -0
- bai_python_hwc/questions/hwc111.txt +25 -0
- bai_python_hwc/questions/hwc112.txt +13 -0
- bai_python_hwc/questions/hwc113.txt +28 -0
- bai_python_hwc/questions/hwc114.txt +35 -0
- bai_python_hwc/questions/hwc115.txt +15 -0
- bai_python_hwc/questions/hwc116.txt +13 -0
- bai_python_hwc/questions/hwc117.txt +14 -0
- bai_python_hwc/questions/hwc118.txt +25 -0
- bai_python_hwc/questions/hwc119.txt +18 -0
- bai_python_hwc/questions/hwc120.txt +23 -0
- bai_python_hwc/questions/hwc121.txt +26 -0
- bai_python_hwc/questions/hwc122.txt +21 -0
- bai_python_hwc/questions/hwc123.txt +21 -0
- bai_python_hwc/questions/hwc124.txt +19 -0
- bai_python_hwc/questions/hwc125.txt +31 -0
- bai_python_hwc/questions/hwc126.txt +18 -0
- bai_python_hwc/questions/hwc127.txt +17 -0
- bai_python_hwc/questions/hwc128.txt +14 -0
- bai_python_hwc/questions/hwc130.txt +23 -0
- bai_python_hwc/questions/hwc131.txt +19 -0
- bai_python_hwc/questions/hwc132.txt +16 -0
- bai_python_hwc/questions/hwc133.txt +39 -0
- bai_python_hwc/questions/hwc134.txt +22 -0
- bai_python_hwc/questions/hwc135.txt +29 -0
- bai_python_hwc/questions/hwc136.txt +20 -0
- bai_python_hwc/questions/hwc201.txt +20 -0
- bai_python_hwc/questions/hwc202.txt +25 -0
- bai_python_hwc/questions/hwc203.txt +26 -0
- bai_python_hwc/questions/hwc204.txt +32 -0
- bai_python_hwc/questions/hwc205.txt +28 -0
- bai_python_hwc/questions/hwc206.txt +28 -0
- bai_python_hwc/questions/hwc207.txt +16 -0
- bai_python_hwc/questions/hwc208.txt +27 -0
- bai_python_hwc/questions/hwc209.txt +15 -0
- bai_python_hwc/questions/hwc210.txt +28 -0
- bai_python_hwc/questions/hwc211.txt +35 -0
- bai_python_hwc/questions/hwc212.txt +29 -0
- bai_python_hwc/questions/hwc213.txt +27 -0
- bai_python_hwc/questions/hwc214.txt +27 -0
- bai_python_hwc/questions/hwc215.txt +28 -0
- bai_python_hwc/questions/hwc216.txt +22 -0
- bai_python_hwc/questions/hwc217.txt +17 -0
- bai_python_hwc/questions/hwc218.txt +18 -0
- bai_python_hwc/questions/hwc219.txt +22 -0
- bai_python_hwc/questions/hwc220.txt +28 -0
- bai_python_hwc/questions/hwc221.txt +18 -0
- bai_python_hwc/questions/hwc222.txt +20 -0
- bai_python_hwc/questions/hwc223.txt +18 -0
- bai_python_hwc/questions/hwc224.txt +23 -0
- bai_python_hwc/questions/hwc225.txt +26 -0
- bai_python_hwc/questions/hwc226.txt +18 -0
- bai_python_hwc/questions/hwc227.txt +15 -0
- bai_python_hwc/questions/hwc228.txt +16 -0
- bai_python_hwc/questions/hwc229.txt +20 -0
- bai_python_hwc/questions/hwc230.txt +18 -0
- bai_python_hwc/questions/hwc231.txt +13 -0
- bai_python_hwc/questions/hwc232.txt +19 -0
- bai_python_hwc/questions/hwc233.txt +21 -0
- bai_python_hwc/questions/hwc234.txt +27 -0
- bai_python_hwc/questions/hwc235.txt +18 -0
- bai_python_hwc/questions/hwc236.txt +23 -0
- bai_python_hwc/questions/hwc237.txt +28 -0
- bai_python_hwc/questions/hwc238.txt +25 -0
- bai_python_hwc/questions/hwc239.txt +28 -0
- bai_python_hwc/questions/hwc240.txt +21 -0
- bai_python_hwc/questions/hwc241.txt +25 -0
- bai_python_hwc/questions/hwc242.txt +23 -0
- bai_python_hwc/questions/hwc243.txt +35 -0
- bai_python_hwc/questions/hwc244.txt +25 -0
- bai_python_hwc/questions/hwc245.txt +24 -0
- bai_python_hwc/questions/hwc246.txt +28 -0
- bai_python_hwc/questions/hwc247.txt +51 -0
- bai_python_hwc/questions/hwc301.txt +23 -0
- bai_python_hwc/questions/hwc302.txt +26 -0
- bai_python_hwc/questions/hwc303.txt +32 -0
- bai_python_hwc/questions/hwc304.txt +32 -0
- bai_python_hwc/questions/hwc305.txt +31 -0
- bai_python_hwc/questions/hwc306.txt +31 -0
- bai_python_hwc/questions/hwc307.txt +29 -0
- bai_python_hwc/questions/hwc308.txt +30 -0
- bai_python_hwc/questions/hwc309.txt +25 -0
- bai_python_hwc/questions/hwc310.txt +15 -0
- bai_python_hwc/questions/hwc311.txt +23 -0
- bai_python_hwc/questions/hwc312.txt +19 -0
- bai_python_hwc/questions/hwc313.txt +26 -0
- bai_python_hwc/questions/hwc314.txt +27 -0
- bai_python_hwc/questions/hwc315.txt +21 -0
- bai_python_hwc/questions/hwc316.txt +36 -0
- bai_python_hwc/questions/hwc317.txt +28 -0
- bai_python_hwc/questions/hwc318.txt +27 -0
- bai_python_hwc/questions/hwc319.txt +26 -0
- bai_python_hwc/questions/hwc320.txt +42 -0
- bai_python_hwc/questions/hwc321.txt +27 -0
- bai_python_hwc/questions/hwc322.txt +26 -0
- bai_python_hwc/questions/hwc323.txt +24 -0
- bai_python_hwc/questions/hwc324.txt +40 -0
- bai_python_hwc/questions/hwc325.txt +21 -0
- bai_python_hwc/questions/hwc326.txt +25 -0
- bai_python_hwc/questions/hwc327.txt +16 -0
- bai_python_hwc/questions/hwc328.txt +15 -0
- bai_python_hwc/questions/hwc329.txt +26 -0
- bai_python_hwc/questions/hwc330.txt +27 -0
- bai_python_hwc/questions/hwc332.txt +26 -0
- bai_python_hwc/questions/hwc401.txt +25 -0
- bai_python_hwc/questions/hwc402.txt +24 -0
- bai_python_hwc/questions/hwc403.txt +37 -0
- bai_python_hwc/questions/hwc404.txt +23 -0
- bai_python_hwc/questions/hwc405.txt +29 -0
- bai_python_hwc/questions/hwc406.txt +34 -0
- bai_python_hwc/questions/hwc407.txt +24 -0
- bai_python_hwc/questions/hwc408.txt +28 -0
- bai_python_hwc/questions/hwc409.txt +25 -0
- bai_python_hwc/questions/hwc410.txt +23 -0
- bai_python_hwc/questions/hwc411.txt +34 -0
- bai_python_hwc/questions/hwc412.txt +29 -0
- bai_python_hwc/questions/hwc413.txt +28 -0
- bai_python_hwc/questions/hwc414.txt +27 -0
- bai_python_hwc/questions/hwc415.txt +27 -0
- bai_python_hwc/questions/hwc416.txt +36 -0
- bai_python_hwc/questions/hwc418.txt +25 -0
- bai_python_hwc/questions/hwc419.txt +28 -0
- bai_python_hwc/questions/hwc421.txt +23 -0
- bai_python_hwc/questions/hwc424.txt +20 -0
- bai_python_hwc/questions/hwc501.txt +23 -0
- bai_python_hwc/questions/hwc502.txt +41 -0
- bai_python_hwc/questions/hwc503.txt +36 -0
- bai_python_hwc/questions/hwc504.txt +18 -0
- bai_python_hwc/questions/hwc505.txt +25 -0
- bai_python_hwc/questions/hwc506.txt +32 -0
- bai_python_hwc/questions/hwc508.txt +24 -0
- bai_python_hwc/questions/hwc509.txt +42 -0
- bai_python_hwc/questions/hwc510.txt +25 -0
- bai_python_hwc/questions/hwc511.txt +23 -0
- bai_python_hwc/questions/hwc513.txt +25 -0
- bai_python_hwc/questions/hwc514.txt +35 -0
- bai_python_hwc/questions/hwc515.txt +46 -0
- bai_python_hwc/questions/hwc516.txt +26 -0
- bai_python_hwc/questions/hwc517.txt +20 -0
- bai_python_hwc/questions/hwc520.txt +27 -0
- bai_python_hwc/questions/hwc526.txt +36 -0
- bai_python_hwc-1.0.0.dist-info/METADATA +41 -0
- bai_python_hwc-1.0.0.dist-info/RECORD +305 -0
- bai_python_hwc-1.0.0.dist-info/WHEEL +5 -0
- bai_python_hwc-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
'''
|
|
4
|
+
请只在 "
|
|
5
|
+
##########start下面可以改动
|
|
6
|
+
|
|
7
|
+
##########end上面可以改动 "
|
|
8
|
+
|
|
9
|
+
中间部分作答,作答行数自由调整
|
|
10
|
+
|
|
11
|
+
请不要使用 input() 函数
|
|
12
|
+
|
|
13
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
14
|
+
|
|
15
|
+
题目:
|
|
16
|
+
给定一个数字列表 data_list,请计算列表中所有“大于10”的数字之和。
|
|
17
|
+
列表数据:[5, 12, 8, 1, 30, 9]
|
|
18
|
+
预期输出结果:42
|
|
19
|
+
'''
|
|
20
|
+
|
|
21
|
+
# 参考答案
|
|
22
|
+
|
|
23
|
+
def TEST_DO_NOT_CHANGE(data_list):
|
|
24
|
+
rlt = None
|
|
25
|
+
##########start下面可以改动
|
|
26
|
+
rlt = 0
|
|
27
|
+
for i in data_list:
|
|
28
|
+
if i > 10:
|
|
29
|
+
rlt = rlt + i
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
##########end上面可以改动
|
|
33
|
+
return rlt
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
###########下面可以修改
|
|
37
|
+
data_list = [5, 12, 8, 1, 30, 9]
|
|
38
|
+
print(TEST_DO_NOT_CHANGE(data_list))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
x=10, y=20, 将两个变量值互换 x=20,y=10。
|
|
16
|
+
'''
|
|
17
|
+
|
|
18
|
+
# 参考答案
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def TEST_DO_NOT_CHANGE(x,y):
|
|
23
|
+
print(x,y)
|
|
24
|
+
##########start下面可以改动
|
|
25
|
+
|
|
26
|
+
x1 = x
|
|
27
|
+
y1 = y
|
|
28
|
+
y = x1
|
|
29
|
+
x = y1
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
##########end上面可以改动
|
|
38
|
+
return x,y
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
###########下面可以修改
|
|
44
|
+
print (TEST_DO_NOT_CHANGE(10,20))
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
判断101-200(包含101和200)之间有哪些素数,按照从小到大保存至 lst_rlt,最后返回该列表。
|
|
16
|
+
提示:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 (此方法并不惟一)
|
|
17
|
+
'''
|
|
18
|
+
|
|
19
|
+
# 参考答案
|
|
20
|
+
|
|
21
|
+
def TEST_DO_NOT_CHANGE():
|
|
22
|
+
lst_rlt=[]
|
|
23
|
+
##########start下面可以改动
|
|
24
|
+
import math
|
|
25
|
+
|
|
26
|
+
for i in range(101, 201):
|
|
27
|
+
prime = True
|
|
28
|
+
|
|
29
|
+
for j in range(2, i):
|
|
30
|
+
if i % j == 0:
|
|
31
|
+
prime = False
|
|
32
|
+
break
|
|
33
|
+
|
|
34
|
+
if prime == True:
|
|
35
|
+
lst_rlt.append(i)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
##########end上面可以改动
|
|
41
|
+
return lst_rlt
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
###########下面可以修改
|
|
46
|
+
print (TEST_DO_NOT_CHANGE())
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
计算并返回x的平方根整数部分,其中x是非负整数。
|
|
16
|
+
由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。
|
|
17
|
+
|
|
18
|
+
示例 1:
|
|
19
|
+
输入: 4
|
|
20
|
+
输出: 2
|
|
21
|
+
|
|
22
|
+
示例 2:
|
|
23
|
+
输入: 8
|
|
24
|
+
输出: 2
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
说明: 8 的平方根是 2.82842..., 由于返回类型是整数,小数部分将被舍去。
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
# 参考答案
|
|
31
|
+
|
|
32
|
+
def TEST_DO_NOT_CHANGE(x):
|
|
33
|
+
print(x)
|
|
34
|
+
rlt = None
|
|
35
|
+
##########start下面可以改动
|
|
36
|
+
|
|
37
|
+
from math import isqrt
|
|
38
|
+
|
|
39
|
+
rlt = isqrt(x)
|
|
40
|
+
|
|
41
|
+
##########end上面可以改动
|
|
42
|
+
return rlt
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
###########下面可以修改
|
|
46
|
+
print(TEST_DO_NOT_CHANGE(4))
|
|
47
|
+
print(TEST_DO_NOT_CHANGE(8))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:实现 str_rlt print(str_rlt)后如下图案(菱形):
|
|
15
|
+
*
|
|
16
|
+
***
|
|
17
|
+
*****
|
|
18
|
+
***
|
|
19
|
+
*
|
|
20
|
+
程序分析:先把图形分成两部分来看待,前三行一个规律,后两行一个规律,利用双重 for 循环,第一层控制行,第二层控制列。
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
# 参考答案
|
|
24
|
+
|
|
25
|
+
def TEST_DO_NOT_CHANGE():
|
|
26
|
+
str_rlt = None
|
|
27
|
+
##########start下面可以改动
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
str_rlt = " *\n ***\n*****\n ***\n *"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
##########end上面可以改动
|
|
38
|
+
return str_rlt
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
###########下面可以修改
|
|
42
|
+
|
|
43
|
+
print (TEST_DO_NOT_CHANGE())
|
|
44
|
+
# 题号:hwc119
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:计算幂次方
|
|
14
|
+
|
|
15
|
+
编写一个 Python 程序,计算并输出给定底数 x 和指数 n 的幂次方结果。
|
|
16
|
+
|
|
17
|
+
幂次方的定义如下:
|
|
18
|
+
|
|
19
|
+
x 的 0 次幂是 1。
|
|
20
|
+
x 的正整数 n 次幂是 x 乘以自己 n 次,即 x^n = x * x * ... * x (n 次)。
|
|
21
|
+
例如,2 的 3 次幂是 2^3 = 2 * 2 * 2 = 8。
|
|
22
|
+
|
|
23
|
+
请编写一个函数 TEST_DO_NOT_CHANGE(x, n),其中 x 为底数,n 为指数,返回 x^n 的结果。
|
|
24
|
+
注:本题为 基础版(只考虑 n ≥ 0,实现方式不限);进阶版(不能用 **,且要处理负指数)见 hwc110。
|
|
25
|
+
'''
|
|
26
|
+
|
|
27
|
+
# 参考答案
|
|
28
|
+
def TEST_DO_NOT_CHANGE(x, n):
|
|
29
|
+
result = None
|
|
30
|
+
##########start下面可以改动
|
|
31
|
+
|
|
32
|
+
result = x ** n
|
|
33
|
+
|
|
34
|
+
##########end上面可以改动
|
|
35
|
+
return result
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
###########下面可以修改
|
|
39
|
+
print(TEST_DO_NOT_CHANGE(2, 3)) # 应该输出 8
|
|
40
|
+
print(TEST_DO_NOT_CHANGE(3, 3)) # 应该输出 27
|
|
41
|
+
print(TEST_DO_NOT_CHANGE(5, 2)) # 应该输出 25
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给你一个由 n 个元素组成的整数数组 nums 和一个整数 k 。
|
|
16
|
+
请你找出平均数最大的、长度为 k 的连续一段(连续子数组),并输出这个最大平均数。
|
|
17
|
+
任何误差小于 10^-5(即 0.00001)的答案都将被视为正确答案。
|
|
18
|
+
|
|
19
|
+
示例 1:
|
|
20
|
+
|
|
21
|
+
输入: nums = [1,12,-5,-6,50,3], k = 4
|
|
22
|
+
输出: 12.75
|
|
23
|
+
解释: 最大平均数 (12-5-6+50)/4 = 51/4 = 12.75
|
|
24
|
+
|
|
25
|
+
示例 2:
|
|
26
|
+
|
|
27
|
+
输入: nums = [5], k = 1
|
|
28
|
+
输出: 5.0
|
|
29
|
+
'''
|
|
30
|
+
|
|
31
|
+
# 参考答案
|
|
32
|
+
def TEST_DO_NOT_CHANGE(nums, k):
|
|
33
|
+
res=0.0
|
|
34
|
+
##########start下面可以改动
|
|
35
|
+
|
|
36
|
+
window = sum(nums[:k])
|
|
37
|
+
best = window
|
|
38
|
+
for right in range(k, len(nums)):
|
|
39
|
+
window += nums[right] - nums[right - k]
|
|
40
|
+
best = max(best, window)
|
|
41
|
+
res = best / k
|
|
42
|
+
|
|
43
|
+
##########end上面可以改动
|
|
44
|
+
return res
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
###########下面可以修改
|
|
48
|
+
|
|
49
|
+
print(TEST_DO_NOT_CHANGE([1,12,-5,-6,50,3],4))
|
|
50
|
+
print(TEST_DO_NOT_CHANGE([5],1))
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
使用冒泡排序方法对以下列表进行排序:
|
|
16
|
+
提示:冒泡排序的步骤:
|
|
17
|
+
1、比较相邻的元素。如果第一个比第二个大,就交换他们两个。
|
|
18
|
+
2、对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。
|
|
19
|
+
3、针对所有的元素重复以上的步骤,除了最后一个。
|
|
20
|
+
4、持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较。
|
|
21
|
+
尝试将以下列表用冒泡法进行排序,结果直接输出排序后的列表
|
|
22
|
+
例如 arr3 = [67,23,8,54,31,49]
|
|
23
|
+
排序后输出的result形式为: [8, 23, 31, 49, 54, 67]
|
|
24
|
+
'''
|
|
25
|
+
|
|
26
|
+
# 参考答案
|
|
27
|
+
def TEST_DO_NOT_CHANGE(arr):
|
|
28
|
+
result = None
|
|
29
|
+
##########start下面可以改动
|
|
30
|
+
|
|
31
|
+
result = arr.copy()
|
|
32
|
+
for end in range(len(result) - 1, 0, -1):
|
|
33
|
+
swapped = False
|
|
34
|
+
for i in range(end):
|
|
35
|
+
if result[i] > result[i + 1]:
|
|
36
|
+
result[i], result[i + 1] = result[i + 1], result[i]
|
|
37
|
+
swapped = True
|
|
38
|
+
if not swapped:
|
|
39
|
+
break
|
|
40
|
+
|
|
41
|
+
##########end上面可以改动
|
|
42
|
+
return result
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
###########下面可以修改
|
|
47
|
+
|
|
48
|
+
arr1 = [51,23,79,11,19,59,66,8,97,72,36,49,81]
|
|
49
|
+
arr2 = [3,78,34,8,56,12,9,24,45]
|
|
50
|
+
arr3 = [67,23,8,54,31,49]
|
|
51
|
+
|
|
52
|
+
print(TEST_DO_NOT_CHANGE(arr1))
|
|
53
|
+
print(TEST_DO_NOT_CHANGE(arr2))
|
|
54
|
+
print(TEST_DO_NOT_CHANGE(arr3))
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目
|
|
15
|
+
给定一个二进制数组, 计算其中最大连续 1 的个数。
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
示例:
|
|
20
|
+
|
|
21
|
+
输入:[1,1,0,1,1,1]
|
|
22
|
+
输出:3
|
|
23
|
+
解释:开头的两位和最后的三位都是连续 1 ,所以最大连续 1 的个数是 3.
|
|
24
|
+
'''
|
|
25
|
+
|
|
26
|
+
# 参考答案
|
|
27
|
+
|
|
28
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
29
|
+
print(nums)
|
|
30
|
+
rlt = None
|
|
31
|
+
##########start下面可以改动
|
|
32
|
+
|
|
33
|
+
rlt = run = 0
|
|
34
|
+
for value in nums:
|
|
35
|
+
run = run + 1 if value == 1 else 0
|
|
36
|
+
rlt = max(rlt, run)
|
|
37
|
+
|
|
38
|
+
##########end上面可以改动
|
|
39
|
+
return rlt
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
###########下面可以修改
|
|
43
|
+
print(TEST_DO_NOT_CHANGE([1,1,0,1,1,1]))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:(改编自计算机二级 Python 真题·综合应用题·枚举考点)
|
|
15
|
+
水仙花数是指一个 3 位正整数,其各位数字的立方和等于它本身。
|
|
16
|
+
例如:153 = 1^3 + 5^3 + 3^3,370 = 3^3 + 7^3 + 0^3。
|
|
17
|
+
请找出 100 ~ 999(含)之间所有的水仙花数,并按从小到大的顺序存入列表返回。
|
|
18
|
+
|
|
19
|
+
示例:
|
|
20
|
+
输入:无参数
|
|
21
|
+
输出:[153, 370, 371, 407]
|
|
22
|
+
'''
|
|
23
|
+
|
|
24
|
+
# 参考答案
|
|
25
|
+
|
|
26
|
+
def TEST_DO_NOT_CHANGE():
|
|
27
|
+
lst_rlt = None
|
|
28
|
+
##########start下面可以改动
|
|
29
|
+
|
|
30
|
+
lst_rlt = []
|
|
31
|
+
for value in range(100, 1000):
|
|
32
|
+
if sum(int(digit) ** 3 for digit in str(value)) == value:
|
|
33
|
+
lst_rlt.append(value)
|
|
34
|
+
|
|
35
|
+
##########end上面可以改动
|
|
36
|
+
return lst_rlt
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
###########下面可以修改
|
|
40
|
+
print(TEST_DO_NOT_CHANGE())
|
|
41
|
+
# 题号:hwc124
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:最高海拔
|
|
14
|
+
有一个自行车手打算进行一场公路骑行,这条路线总共由 n + 1 个不同海拔的点组成。自行车手从海拔为 0 的点 0 开始骑行。
|
|
15
|
+
给你一个长度为 n 的整数数组 gain ,其中 gain[i] 表示从第 i 个点骑到第 i+1 个点时海拔变化了多少(正数表示上坡升高,负数表示下坡降低)。请你返回整条路线中 最高点的海拔 。
|
|
16
|
+
|
|
17
|
+
提示:
|
|
18
|
+
n == gain.length
|
|
19
|
+
1 <= n <= 100
|
|
20
|
+
-100 <= gain[i] <= 100
|
|
21
|
+
|
|
22
|
+
示例 1:
|
|
23
|
+
|
|
24
|
+
输入:gain = [-5,1,5,0,-7]
|
|
25
|
+
输出:1
|
|
26
|
+
解释:海拔高度依次为 [0,-5,-4,1,1,-6] 。最高海拔为 1 。
|
|
27
|
+
|
|
28
|
+
示例 2:
|
|
29
|
+
|
|
30
|
+
输入:gain = [-4,-3,-2,-1,4,3,2]
|
|
31
|
+
输出:0
|
|
32
|
+
解释:海拔高度依次为 [0,-4,-7,-9,-10,-6,-3,-1] 。最高海拔为 0 。
|
|
33
|
+
'''
|
|
34
|
+
|
|
35
|
+
# 参考答案
|
|
36
|
+
def TEST_DO_NOT_CHANGE(gain_list):
|
|
37
|
+
output = None
|
|
38
|
+
##########start下面可以改动
|
|
39
|
+
|
|
40
|
+
height = output = 0
|
|
41
|
+
for gain in gain_list:
|
|
42
|
+
height += gain
|
|
43
|
+
output = max(output, height)
|
|
44
|
+
|
|
45
|
+
##########end上面可以改动
|
|
46
|
+
return output
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
###########下面可以修改
|
|
50
|
+
print(TEST_DO_NOT_CHANGE([1,2,1,0,3,0,2,5]))
|
|
51
|
+
print(TEST_DO_NOT_CHANGE([1,0,-1,5,-6,7]))
|
|
52
|
+
print(TEST_DO_NOT_CHANGE([0,1,2,3,-10,7,2]))
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
将整数列表中所有的偶数摘选出来并输出一个新的列表。
|
|
16
|
+
例如:nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]输出结果为[2, 4, 6, 8, 10]
|
|
17
|
+
请将以下列表中的偶数筛选出来:
|
|
18
|
+
num1 = [11,16,26,7,31]
|
|
19
|
+
num2 = [13,18,21,37,42]
|
|
20
|
+
num3 = [31,17,46,12,77]
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
# 参考答案
|
|
24
|
+
|
|
25
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
26
|
+
result = None
|
|
27
|
+
##########start下面可以改动
|
|
28
|
+
|
|
29
|
+
result = [value for value in nums if value % 2 == 0]
|
|
30
|
+
|
|
31
|
+
##########end上面可以改动
|
|
32
|
+
return result
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
###########下面可以修改
|
|
35
|
+
num1 = [11,16,26,7,31]
|
|
36
|
+
num2 = [13,18,21,37,42]
|
|
37
|
+
num3 = [31,17,46,12,77]
|
|
38
|
+
print(TEST_DO_NOT_CHANGE(num1))
|
|
39
|
+
print(TEST_DO_NOT_CHANGE(num2))
|
|
40
|
+
print(TEST_DO_NOT_CHANGE(num3))
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
已知一个3*3矩阵A,A的元素依次为1-9的平方
|
|
16
|
+
|1^2 2^2 3^2|
|
|
17
|
+
A=|4^2 5^2 6^2|,求该矩阵主对角线元素之和(主对角线即从左上方到右下方的那条斜线,行号和列号相同的元素:1^2、5^2、9^2)。
|
|
18
|
+
|7^2 8^2 9^2|
|
|
19
|
+
程序分析:利用双重for循环控制输入二维数组,再将a[i][i]累加后输出。
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
# 参考答案
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def TEST_DO_NOT_CHANGE():
|
|
26
|
+
rlt_sum=0
|
|
27
|
+
A = [[1**2, 2**2, 3**2],
|
|
28
|
+
[4**2, 5**2, 6**2],
|
|
29
|
+
[7**2, 8**2, 9**2],
|
|
30
|
+
]
|
|
31
|
+
##########start下面可以改动
|
|
32
|
+
|
|
33
|
+
rlt_sum = sum(A[i][i] for i in range(len(A)))
|
|
34
|
+
|
|
35
|
+
##########end上面可以改动
|
|
36
|
+
return rlt_sum
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
###########下面可以修改
|
|
41
|
+
print (TEST_DO_NOT_CHANGE())
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
编写一个函数:当 n 为偶数时,返回 1/2+1/4+...+1/n;当 n 为奇数时,返回
|
|
16
|
+
1/1+1/3+...+1/n。两个求和过程分别由辅助函数实现。
|
|
17
|
+
'''
|
|
18
|
+
|
|
19
|
+
# 参考答案
|
|
20
|
+
|
|
21
|
+
def TEST_DO_NOT_CHANGE(n):
|
|
22
|
+
rlt = None
|
|
23
|
+
##########start下面可以改动
|
|
24
|
+
|
|
25
|
+
def even_sum(limit):
|
|
26
|
+
return sum(1 / i for i in range(2, limit + 1, 2))
|
|
27
|
+
|
|
28
|
+
def odd_sum(limit):
|
|
29
|
+
return sum(1 / i for i in range(1, limit + 1, 2))
|
|
30
|
+
|
|
31
|
+
rlt = odd_sum(n) if n % 2 else even_sum(n)
|
|
32
|
+
|
|
33
|
+
##########end上面可以改动
|
|
34
|
+
return rlt
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
###########下面可以修改
|
|
38
|
+
print(TEST_DO_NOT_CHANGE(9))
|
|
39
|
+
print(TEST_DO_NOT_CHANGE(8))
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给定两个字符串 s1 和 s2,请编写一个程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。
|
|
16
|
+
|
|
17
|
+
示例 1:
|
|
18
|
+
|
|
19
|
+
输入: s1 = "abc", s2 = "bca"
|
|
20
|
+
输出: True
|
|
21
|
+
示例 2:
|
|
22
|
+
|
|
23
|
+
输入: s1 = "abc", s2 = "bad"
|
|
24
|
+
输出: False
|
|
25
|
+
说明:两个字符串长度相同且仅由字符组成;字符出现次数完全相同时返回 True,否则返回 False。
|
|
26
|
+
'''
|
|
27
|
+
|
|
28
|
+
# 参考答案
|
|
29
|
+
def TEST_DO_NOT_CHANGE(s1,s2):
|
|
30
|
+
print(s1,s2)
|
|
31
|
+
rlt = None
|
|
32
|
+
##########start下面可以改动
|
|
33
|
+
|
|
34
|
+
from collections import Counter
|
|
35
|
+
|
|
36
|
+
rlt = Counter(s1) == Counter(s2)
|
|
37
|
+
|
|
38
|
+
##########end上面可以改动
|
|
39
|
+
return rlt
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
###########下面可以修改
|
|
44
|
+
s1 = "abc"
|
|
45
|
+
s2 = "bca"
|
|
46
|
+
print(TEST_DO_NOT_CHANGE(s1,s2))
|