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.
Files changed (305) hide show
  1. bai_python_hwc/__init__.py +46 -0
  2. bai_python_hwc/answers/hwc101.py +38 -0
  3. bai_python_hwc/answers/hwc103.py +52 -0
  4. bai_python_hwc/answers/hwc104.py +45 -0
  5. bai_python_hwc/answers/hwc105.py +45 -0
  6. bai_python_hwc/answers/hwc106.py +56 -0
  7. bai_python_hwc/answers/hwc107.py +49 -0
  8. bai_python_hwc/answers/hwc108.py +45 -0
  9. bai_python_hwc/answers/hwc109.py +50 -0
  10. bai_python_hwc/answers/hwc110.py +42 -0
  11. bai_python_hwc/answers/hwc111.py +47 -0
  12. bai_python_hwc/answers/hwc112.py +42 -0
  13. bai_python_hwc/answers/hwc113.py +58 -0
  14. bai_python_hwc/answers/hwc114.py +58 -0
  15. bai_python_hwc/answers/hwc115.py +38 -0
  16. bai_python_hwc/answers/hwc116.py +44 -0
  17. bai_python_hwc/answers/hwc117.py +46 -0
  18. bai_python_hwc/answers/hwc118.py +47 -0
  19. bai_python_hwc/answers/hwc119.py +44 -0
  20. bai_python_hwc/answers/hwc120.py +41 -0
  21. bai_python_hwc/answers/hwc121.py +50 -0
  22. bai_python_hwc/answers/hwc122.py +54 -0
  23. bai_python_hwc/answers/hwc123.py +43 -0
  24. bai_python_hwc/answers/hwc124.py +41 -0
  25. bai_python_hwc/answers/hwc125.py +52 -0
  26. bai_python_hwc/answers/hwc126.py +40 -0
  27. bai_python_hwc/answers/hwc127.py +41 -0
  28. bai_python_hwc/answers/hwc128.py +39 -0
  29. bai_python_hwc/answers/hwc130.py +46 -0
  30. bai_python_hwc/answers/hwc131.py +46 -0
  31. bai_python_hwc/answers/hwc132.py +38 -0
  32. bai_python_hwc/answers/hwc133.py +61 -0
  33. bai_python_hwc/answers/hwc134.py +45 -0
  34. bai_python_hwc/answers/hwc135.py +49 -0
  35. bai_python_hwc/answers/hwc136.py +43 -0
  36. bai_python_hwc/answers/hwc201.py +47 -0
  37. bai_python_hwc/answers/hwc202.py +47 -0
  38. bai_python_hwc/answers/hwc203.py +48 -0
  39. bai_python_hwc/answers/hwc204.py +61 -0
  40. bai_python_hwc/answers/hwc205.py +56 -0
  41. bai_python_hwc/answers/hwc206.py +53 -0
  42. bai_python_hwc/answers/hwc207.py +43 -0
  43. bai_python_hwc/answers/hwc208.py +57 -0
  44. bai_python_hwc/answers/hwc209.py +42 -0
  45. bai_python_hwc/answers/hwc210.py +46 -0
  46. bai_python_hwc/answers/hwc211.py +62 -0
  47. bai_python_hwc/answers/hwc212.py +58 -0
  48. bai_python_hwc/answers/hwc213.py +54 -0
  49. bai_python_hwc/answers/hwc214.py +55 -0
  50. bai_python_hwc/answers/hwc215.py +53 -0
  51. bai_python_hwc/answers/hwc216.py +50 -0
  52. bai_python_hwc/answers/hwc217.py +38 -0
  53. bai_python_hwc/answers/hwc218.py +44 -0
  54. bai_python_hwc/answers/hwc219.py +49 -0
  55. bai_python_hwc/answers/hwc220.py +58 -0
  56. bai_python_hwc/answers/hwc221.py +49 -0
  57. bai_python_hwc/answers/hwc222.py +48 -0
  58. bai_python_hwc/answers/hwc223.py +39 -0
  59. bai_python_hwc/answers/hwc224.py +47 -0
  60. bai_python_hwc/answers/hwc225.py +50 -0
  61. bai_python_hwc/answers/hwc226.py +41 -0
  62. bai_python_hwc/answers/hwc227.py +40 -0
  63. bai_python_hwc/answers/hwc228.py +41 -0
  64. bai_python_hwc/answers/hwc229.py +51 -0
  65. bai_python_hwc/answers/hwc230.py +41 -0
  66. bai_python_hwc/answers/hwc231.py +39 -0
  67. bai_python_hwc/answers/hwc232.py +44 -0
  68. bai_python_hwc/answers/hwc233.py +49 -0
  69. bai_python_hwc/answers/hwc234.py +52 -0
  70. bai_python_hwc/answers/hwc235.py +45 -0
  71. bai_python_hwc/answers/hwc236.py +53 -0
  72. bai_python_hwc/answers/hwc237.py +56 -0
  73. bai_python_hwc/answers/hwc238.py +52 -0
  74. bai_python_hwc/answers/hwc239.py +60 -0
  75. bai_python_hwc/answers/hwc240.py +45 -0
  76. bai_python_hwc/answers/hwc241.py +48 -0
  77. bai_python_hwc/answers/hwc242.py +50 -0
  78. bai_python_hwc/answers/hwc243.py +61 -0
  79. bai_python_hwc/answers/hwc244.py +61 -0
  80. bai_python_hwc/answers/hwc245.py +47 -0
  81. bai_python_hwc/answers/hwc246.py +52 -0
  82. bai_python_hwc/answers/hwc247.py +76 -0
  83. bai_python_hwc/answers/hwc301.py +44 -0
  84. bai_python_hwc/answers/hwc302.py +53 -0
  85. bai_python_hwc/answers/hwc303.py +63 -0
  86. bai_python_hwc/answers/hwc304.py +56 -0
  87. bai_python_hwc/answers/hwc305.py +59 -0
  88. bai_python_hwc/answers/hwc306.py +60 -0
  89. bai_python_hwc/answers/hwc307.py +50 -0
  90. bai_python_hwc/answers/hwc308.py +59 -0
  91. bai_python_hwc/answers/hwc309.py +48 -0
  92. bai_python_hwc/answers/hwc310.py +38 -0
  93. bai_python_hwc/answers/hwc311.py +48 -0
  94. bai_python_hwc/answers/hwc312.py +49 -0
  95. bai_python_hwc/answers/hwc313.py +54 -0
  96. bai_python_hwc/answers/hwc314.py +49 -0
  97. bai_python_hwc/answers/hwc315.py +63 -0
  98. bai_python_hwc/answers/hwc316.py +65 -0
  99. bai_python_hwc/answers/hwc317.py +57 -0
  100. bai_python_hwc/answers/hwc318.py +55 -0
  101. bai_python_hwc/answers/hwc319.py +50 -0
  102. bai_python_hwc/answers/hwc320.py +84 -0
  103. bai_python_hwc/answers/hwc321.py +49 -0
  104. bai_python_hwc/answers/hwc322.py +49 -0
  105. bai_python_hwc/answers/hwc323.py +69 -0
  106. bai_python_hwc/answers/hwc324.py +66 -0
  107. bai_python_hwc/answers/hwc325.py +49 -0
  108. bai_python_hwc/answers/hwc326.py +53 -0
  109. bai_python_hwc/answers/hwc327.py +38 -0
  110. bai_python_hwc/answers/hwc328.py +50 -0
  111. bai_python_hwc/answers/hwc329.py +59 -0
  112. bai_python_hwc/answers/hwc330.py +45 -0
  113. bai_python_hwc/answers/hwc332.py +57 -0
  114. bai_python_hwc/answers/hwc401.py +50 -0
  115. bai_python_hwc/answers/hwc402.py +43 -0
  116. bai_python_hwc/answers/hwc403.py +73 -0
  117. bai_python_hwc/answers/hwc404.py +51 -0
  118. bai_python_hwc/answers/hwc405.py +62 -0
  119. bai_python_hwc/answers/hwc406.py +66 -0
  120. bai_python_hwc/answers/hwc407.py +49 -0
  121. bai_python_hwc/answers/hwc408.py +67 -0
  122. bai_python_hwc/answers/hwc409.py +51 -0
  123. bai_python_hwc/answers/hwc410.py +52 -0
  124. bai_python_hwc/answers/hwc411.py +57 -0
  125. bai_python_hwc/answers/hwc412.py +53 -0
  126. bai_python_hwc/answers/hwc413.py +65 -0
  127. bai_python_hwc/answers/hwc414.py +50 -0
  128. bai_python_hwc/answers/hwc415.py +61 -0
  129. bai_python_hwc/answers/hwc416.py +69 -0
  130. bai_python_hwc/answers/hwc418.py +47 -0
  131. bai_python_hwc/answers/hwc419.py +62 -0
  132. bai_python_hwc/answers/hwc421.py +51 -0
  133. bai_python_hwc/answers/hwc424.py +48 -0
  134. bai_python_hwc/answers/hwc501.py +63 -0
  135. bai_python_hwc/answers/hwc502.py +69 -0
  136. bai_python_hwc/answers/hwc503.py +75 -0
  137. bai_python_hwc/answers/hwc504.py +52 -0
  138. bai_python_hwc/answers/hwc505.py +63 -0
  139. bai_python_hwc/answers/hwc506.py +61 -0
  140. bai_python_hwc/answers/hwc508.py +60 -0
  141. bai_python_hwc/answers/hwc509.py +85 -0
  142. bai_python_hwc/answers/hwc510.py +56 -0
  143. bai_python_hwc/answers/hwc511.py +52 -0
  144. bai_python_hwc/answers/hwc513.py +63 -0
  145. bai_python_hwc/answers/hwc514.py +74 -0
  146. bai_python_hwc/answers/hwc515.py +83 -0
  147. bai_python_hwc/answers/hwc516.py +67 -0
  148. bai_python_hwc/answers/hwc517.py +46 -0
  149. bai_python_hwc/answers/hwc520.py +54 -0
  150. bai_python_hwc/answers/hwc526.py +58 -0
  151. bai_python_hwc/attachments/hwc424.pdf +0 -0
  152. bai_python_hwc/attachments/hwc501.pdf +0 -0
  153. bai_python_hwc/questions/hwc101.txt +17 -0
  154. bai_python_hwc/questions/hwc103.txt +27 -0
  155. bai_python_hwc/questions/hwc104.txt +22 -0
  156. bai_python_hwc/questions/hwc105.txt +23 -0
  157. bai_python_hwc/questions/hwc106.txt +26 -0
  158. bai_python_hwc/questions/hwc107.txt +29 -0
  159. bai_python_hwc/questions/hwc108.txt +18 -0
  160. bai_python_hwc/questions/hwc109.txt +24 -0
  161. bai_python_hwc/questions/hwc110.txt +16 -0
  162. bai_python_hwc/questions/hwc111.txt +25 -0
  163. bai_python_hwc/questions/hwc112.txt +13 -0
  164. bai_python_hwc/questions/hwc113.txt +28 -0
  165. bai_python_hwc/questions/hwc114.txt +35 -0
  166. bai_python_hwc/questions/hwc115.txt +15 -0
  167. bai_python_hwc/questions/hwc116.txt +13 -0
  168. bai_python_hwc/questions/hwc117.txt +14 -0
  169. bai_python_hwc/questions/hwc118.txt +25 -0
  170. bai_python_hwc/questions/hwc119.txt +18 -0
  171. bai_python_hwc/questions/hwc120.txt +23 -0
  172. bai_python_hwc/questions/hwc121.txt +26 -0
  173. bai_python_hwc/questions/hwc122.txt +21 -0
  174. bai_python_hwc/questions/hwc123.txt +21 -0
  175. bai_python_hwc/questions/hwc124.txt +19 -0
  176. bai_python_hwc/questions/hwc125.txt +31 -0
  177. bai_python_hwc/questions/hwc126.txt +18 -0
  178. bai_python_hwc/questions/hwc127.txt +17 -0
  179. bai_python_hwc/questions/hwc128.txt +14 -0
  180. bai_python_hwc/questions/hwc130.txt +23 -0
  181. bai_python_hwc/questions/hwc131.txt +19 -0
  182. bai_python_hwc/questions/hwc132.txt +16 -0
  183. bai_python_hwc/questions/hwc133.txt +39 -0
  184. bai_python_hwc/questions/hwc134.txt +22 -0
  185. bai_python_hwc/questions/hwc135.txt +29 -0
  186. bai_python_hwc/questions/hwc136.txt +20 -0
  187. bai_python_hwc/questions/hwc201.txt +20 -0
  188. bai_python_hwc/questions/hwc202.txt +25 -0
  189. bai_python_hwc/questions/hwc203.txt +26 -0
  190. bai_python_hwc/questions/hwc204.txt +32 -0
  191. bai_python_hwc/questions/hwc205.txt +28 -0
  192. bai_python_hwc/questions/hwc206.txt +28 -0
  193. bai_python_hwc/questions/hwc207.txt +16 -0
  194. bai_python_hwc/questions/hwc208.txt +27 -0
  195. bai_python_hwc/questions/hwc209.txt +15 -0
  196. bai_python_hwc/questions/hwc210.txt +28 -0
  197. bai_python_hwc/questions/hwc211.txt +35 -0
  198. bai_python_hwc/questions/hwc212.txt +29 -0
  199. bai_python_hwc/questions/hwc213.txt +27 -0
  200. bai_python_hwc/questions/hwc214.txt +27 -0
  201. bai_python_hwc/questions/hwc215.txt +28 -0
  202. bai_python_hwc/questions/hwc216.txt +22 -0
  203. bai_python_hwc/questions/hwc217.txt +17 -0
  204. bai_python_hwc/questions/hwc218.txt +18 -0
  205. bai_python_hwc/questions/hwc219.txt +22 -0
  206. bai_python_hwc/questions/hwc220.txt +28 -0
  207. bai_python_hwc/questions/hwc221.txt +18 -0
  208. bai_python_hwc/questions/hwc222.txt +20 -0
  209. bai_python_hwc/questions/hwc223.txt +18 -0
  210. bai_python_hwc/questions/hwc224.txt +23 -0
  211. bai_python_hwc/questions/hwc225.txt +26 -0
  212. bai_python_hwc/questions/hwc226.txt +18 -0
  213. bai_python_hwc/questions/hwc227.txt +15 -0
  214. bai_python_hwc/questions/hwc228.txt +16 -0
  215. bai_python_hwc/questions/hwc229.txt +20 -0
  216. bai_python_hwc/questions/hwc230.txt +18 -0
  217. bai_python_hwc/questions/hwc231.txt +13 -0
  218. bai_python_hwc/questions/hwc232.txt +19 -0
  219. bai_python_hwc/questions/hwc233.txt +21 -0
  220. bai_python_hwc/questions/hwc234.txt +27 -0
  221. bai_python_hwc/questions/hwc235.txt +18 -0
  222. bai_python_hwc/questions/hwc236.txt +23 -0
  223. bai_python_hwc/questions/hwc237.txt +28 -0
  224. bai_python_hwc/questions/hwc238.txt +25 -0
  225. bai_python_hwc/questions/hwc239.txt +28 -0
  226. bai_python_hwc/questions/hwc240.txt +21 -0
  227. bai_python_hwc/questions/hwc241.txt +25 -0
  228. bai_python_hwc/questions/hwc242.txt +23 -0
  229. bai_python_hwc/questions/hwc243.txt +35 -0
  230. bai_python_hwc/questions/hwc244.txt +25 -0
  231. bai_python_hwc/questions/hwc245.txt +24 -0
  232. bai_python_hwc/questions/hwc246.txt +28 -0
  233. bai_python_hwc/questions/hwc247.txt +51 -0
  234. bai_python_hwc/questions/hwc301.txt +23 -0
  235. bai_python_hwc/questions/hwc302.txt +26 -0
  236. bai_python_hwc/questions/hwc303.txt +32 -0
  237. bai_python_hwc/questions/hwc304.txt +32 -0
  238. bai_python_hwc/questions/hwc305.txt +31 -0
  239. bai_python_hwc/questions/hwc306.txt +31 -0
  240. bai_python_hwc/questions/hwc307.txt +29 -0
  241. bai_python_hwc/questions/hwc308.txt +30 -0
  242. bai_python_hwc/questions/hwc309.txt +25 -0
  243. bai_python_hwc/questions/hwc310.txt +15 -0
  244. bai_python_hwc/questions/hwc311.txt +23 -0
  245. bai_python_hwc/questions/hwc312.txt +19 -0
  246. bai_python_hwc/questions/hwc313.txt +26 -0
  247. bai_python_hwc/questions/hwc314.txt +27 -0
  248. bai_python_hwc/questions/hwc315.txt +21 -0
  249. bai_python_hwc/questions/hwc316.txt +36 -0
  250. bai_python_hwc/questions/hwc317.txt +28 -0
  251. bai_python_hwc/questions/hwc318.txt +27 -0
  252. bai_python_hwc/questions/hwc319.txt +26 -0
  253. bai_python_hwc/questions/hwc320.txt +42 -0
  254. bai_python_hwc/questions/hwc321.txt +27 -0
  255. bai_python_hwc/questions/hwc322.txt +26 -0
  256. bai_python_hwc/questions/hwc323.txt +24 -0
  257. bai_python_hwc/questions/hwc324.txt +40 -0
  258. bai_python_hwc/questions/hwc325.txt +21 -0
  259. bai_python_hwc/questions/hwc326.txt +25 -0
  260. bai_python_hwc/questions/hwc327.txt +16 -0
  261. bai_python_hwc/questions/hwc328.txt +15 -0
  262. bai_python_hwc/questions/hwc329.txt +26 -0
  263. bai_python_hwc/questions/hwc330.txt +27 -0
  264. bai_python_hwc/questions/hwc332.txt +26 -0
  265. bai_python_hwc/questions/hwc401.txt +25 -0
  266. bai_python_hwc/questions/hwc402.txt +24 -0
  267. bai_python_hwc/questions/hwc403.txt +37 -0
  268. bai_python_hwc/questions/hwc404.txt +23 -0
  269. bai_python_hwc/questions/hwc405.txt +29 -0
  270. bai_python_hwc/questions/hwc406.txt +34 -0
  271. bai_python_hwc/questions/hwc407.txt +24 -0
  272. bai_python_hwc/questions/hwc408.txt +28 -0
  273. bai_python_hwc/questions/hwc409.txt +25 -0
  274. bai_python_hwc/questions/hwc410.txt +23 -0
  275. bai_python_hwc/questions/hwc411.txt +34 -0
  276. bai_python_hwc/questions/hwc412.txt +29 -0
  277. bai_python_hwc/questions/hwc413.txt +28 -0
  278. bai_python_hwc/questions/hwc414.txt +27 -0
  279. bai_python_hwc/questions/hwc415.txt +27 -0
  280. bai_python_hwc/questions/hwc416.txt +36 -0
  281. bai_python_hwc/questions/hwc418.txt +25 -0
  282. bai_python_hwc/questions/hwc419.txt +28 -0
  283. bai_python_hwc/questions/hwc421.txt +23 -0
  284. bai_python_hwc/questions/hwc424.txt +20 -0
  285. bai_python_hwc/questions/hwc501.txt +23 -0
  286. bai_python_hwc/questions/hwc502.txt +41 -0
  287. bai_python_hwc/questions/hwc503.txt +36 -0
  288. bai_python_hwc/questions/hwc504.txt +18 -0
  289. bai_python_hwc/questions/hwc505.txt +25 -0
  290. bai_python_hwc/questions/hwc506.txt +32 -0
  291. bai_python_hwc/questions/hwc508.txt +24 -0
  292. bai_python_hwc/questions/hwc509.txt +42 -0
  293. bai_python_hwc/questions/hwc510.txt +25 -0
  294. bai_python_hwc/questions/hwc511.txt +23 -0
  295. bai_python_hwc/questions/hwc513.txt +25 -0
  296. bai_python_hwc/questions/hwc514.txt +35 -0
  297. bai_python_hwc/questions/hwc515.txt +46 -0
  298. bai_python_hwc/questions/hwc516.txt +26 -0
  299. bai_python_hwc/questions/hwc517.txt +20 -0
  300. bai_python_hwc/questions/hwc520.txt +27 -0
  301. bai_python_hwc/questions/hwc526.txt +36 -0
  302. bai_python_hwc-1.0.0.dist-info/METADATA +41 -0
  303. bai_python_hwc-1.0.0.dist-info/RECORD +305 -0
  304. bai_python_hwc-1.0.0.dist-info/WHEEL +5 -0
  305. bai_python_hwc-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,46 @@
1
+ """按原题号查阅 Python 练习。"""
2
+
3
+ from dataclasses import dataclass
4
+ from importlib.resources import files
5
+ from types import MappingProxyType
6
+
7
+ __all__ = ["bank"]
8
+
9
+ _content = files(__name__)
10
+ _questions = _content.joinpath("questions")
11
+ _answers = _content.joinpath("answers")
12
+ _attachments = _content.joinpath("attachments")
13
+ _answer_marker = "\n# 参考答案\n"
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class _Exercise:
18
+ number: int
19
+
20
+ @property
21
+ def q(self) -> str:
22
+ """返回原题文本。"""
23
+ return _questions.joinpath(f"hwc{self.number}.txt").read_text(encoding="utf-8").rstrip("\n")
24
+
25
+ @property
26
+ def a(self) -> str:
27
+ """返回原题及可运行的参考答案。"""
28
+ source = _answers.joinpath(f"hwc{self.number}.py").read_text(encoding="utf-8")
29
+ _, _, answer = source.partition(_answer_marker)
30
+ return f"{self.q}\n\n参考答案(Python)\n\n{answer.strip()}"
31
+
32
+ @property
33
+ def pdf(self):
34
+ """返回原 PDF 附件。没有附件时返回 None。"""
35
+ attachment = _attachments.joinpath(f"hwc{self.number}.pdf")
36
+ return attachment if attachment.is_file() else None
37
+
38
+
39
+ bank = MappingProxyType({
40
+ number: _Exercise(number)
41
+ for number in sorted(
42
+ int(path.name.removeprefix("hwc").removesuffix(".txt"))
43
+ for path in _questions.iterdir()
44
+ if path.name.startswith("hwc") and path.name.endswith(".txt")
45
+ )
46
+ })
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 给你一个列表,删除列表的倒数第 n 个元素,并且返回修改后的列表。
16
+
17
+ 示例:
18
+ 输入:lst = [1,2,3,4,5], n = 2
19
+ 输出:[1,2,3,5]
20
+ '''
21
+
22
+ # 参考答案
23
+
24
+ def TEST_DO_NOT_CHANGE(lst, n):
25
+ lst_rlt = []
26
+ ##########start下面可以改动
27
+
28
+ ashbin = lst.pop(-n)
29
+ lst_rlt = lst
30
+
31
+ ##########end上面可以改动
32
+ return lst_rlt
33
+
34
+ if __name__ == "__main__":
35
+ ###########下面可以修改
36
+ print(TEST_DO_NOT_CHANGE( [1,2,3,4,5],2))
37
+ print(TEST_DO_NOT_CHANGE([1],1))
38
+ print(TEST_DO_NOT_CHANGE([1,2],1))
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 给定一个按升序排列(从小到大)的数组和一个目标值,在数组中找到目标值,并返回其索引(下标,从 0 开始数)。
16
+ 如果目标值不存在于数组中,返回它应该插入的位置(插进去之后数组仍然保持升序)。
17
+ 你可以假设数组中无重复元素。
18
+
19
+ 示例 1:
20
+ 输入: [1,3,5,6], 5
21
+ 输出: 2
22
+
23
+ 示例2:
24
+ 输入: [1,3,5,6], 2
25
+ 输出: 1
26
+
27
+ 示例 3:
28
+ 输入: [1,3,5,6], 7
29
+ 输出: 4
30
+ '''
31
+
32
+ # 参考答案
33
+
34
+ def TEST_DO_NOT_CHANGE(nums, target):
35
+ index = None
36
+ ##########start下面可以改动
37
+
38
+ if target in nums:
39
+ index = nums.index(target)
40
+ else:
41
+ nums.append(target)
42
+ nums.sort()
43
+ index = nums.index(target)
44
+
45
+ ##########end上面可以改动
46
+ return index
47
+
48
+ if __name__ == "__main__":
49
+ ###########下面可以修改
50
+ print(TEST_DO_NOT_CHANGE([1,3,5,6],5))
51
+ print(TEST_DO_NOT_CHANGE([1,3,5,6],2))
52
+ print(TEST_DO_NOT_CHANGE([1,3,5,6],7))
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 给你一个字符串 s,由若干单词组成,单词之间用空格隔开。返回字符串中最后一个单词的长度。如果不存在最后一个单词,请返回 0。
16
+ 单词 是指仅由字母组成、不包含任何空格字符的最大子字符串。
17
+
18
+ 示例 1:
19
+ 输入:s = "Hello World"
20
+ 输出:5
21
+
22
+ 示例 2:
23
+ 输入:s = " "
24
+ 输出:0
25
+ '''
26
+
27
+ # 参考答案
28
+
29
+ def TEST_DO_NOT_CHANGE(s):
30
+ length = None
31
+ ##########start下面可以改动
32
+
33
+ words_list = s.split()
34
+ if words_list == []:
35
+ length = 0
36
+ else:
37
+ length = len(words_list[-1])
38
+
39
+ ##########end上面可以改动
40
+ return length
41
+
42
+ if __name__ == "__main__":
43
+ ###########下面可以修改
44
+ print(TEST_DO_NOT_CHANGE("Hello World"))
45
+ print(TEST_DO_NOT_CHANGE(" "))
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 给定一个整数 n,返回 n! 结果尾数中零的数量。
16
+
17
+ 示例 1:
18
+ 输入: 3
19
+ 输出: 0
20
+ 解释:3! = 6, 尾数中没有零。
21
+
22
+ 示例2:
23
+ 输入: 5
24
+ 输出: 1
25
+ 解释:5! = 120, 尾数中有 1 个零.
26
+ '''
27
+
28
+ # 参考答案
29
+
30
+ def TEST_DO_NOT_CHANGE(n):
31
+ count = None
32
+ ##########start下面可以改动
33
+
34
+ count = 0
35
+ while n >= 5:
36
+ n //= 5
37
+ count += n
38
+
39
+ ##########end上面可以改动
40
+ return count
41
+
42
+ if __name__ == "__main__":
43
+ ###########下面可以修改
44
+ print(TEST_DO_NOT_CHANGE(3))
45
+ print(TEST_DO_NOT_CHANGE(5))
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目
15
+ 给定一个整数数组,判断是否存在重复元素。
16
+ 如果存在一值在数组中出现至少两次,函数返回 True 。如果数组中每个元素都不相同,则返回 False 。
17
+
18
+ 示例 1:
19
+ 输入: [1,2,3,1]
20
+ 输出: True
21
+
22
+ 示例 2:
23
+ 输入: [1,2,3,4]
24
+ 输出: False
25
+
26
+ 示例3:
27
+ 输入: [1,1,1,3,3,4,3,2,4,2]
28
+ 输出: True
29
+ '''
30
+
31
+ # 参考答案
32
+
33
+ def TEST_DO_NOT_CHANGE(nums):
34
+ has_duplicate = None
35
+ ##########start下面可以改动
36
+ nums.sort()
37
+ list_len = len(nums)
38
+ if list_len == 0 or list_len == 1:
39
+ has_duplicate = False
40
+ else:
41
+ while list_len > 1:
42
+ if nums[list_len-1] == nums[list_len-2]:
43
+ list_len = 0
44
+ has_duplicate = True
45
+ else:
46
+ list_len = list_len -1
47
+ has_duplicate = False
48
+
49
+ ##########end上面可以改动
50
+ return has_duplicate
51
+
52
+ if __name__ == "__main__":
53
+ ###########下面可以修改
54
+ print(TEST_DO_NOT_CHANGE([1,2,3,1]))
55
+ print(TEST_DO_NOT_CHANGE([1,2,3,4]))
56
+ print(TEST_DO_NOT_CHANGE([1,1,1,3,3,4,3,2,4,2]))
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目
15
+ 给定一个整数,编写一个函数来判断它是否是 2 的幂次方。
16
+ (2 的幂次方指 1, 2, 4, 8, 16, 32 ... 这类数,即 2 的 0 次方、1 次方、2 次方……)
17
+ 注意:0 和负数都不是 2 的幂次方,应返回 False。
18
+
19
+ 示例1:
20
+ 输入: 1
21
+ 输出: True
22
+ 解释: 2^0= 1
23
+
24
+ 示例 2:
25
+ 输入: 16
26
+ 输出: True
27
+ 解释: 2^4= 16
28
+
29
+ 示例 3:
30
+ 输入: 218
31
+ 输出: False
32
+ '''
33
+
34
+ # 参考答案
35
+
36
+ def TEST_DO_NOT_CHANGE(n):
37
+ is_power = None
38
+ ##########start下面可以改动
39
+
40
+ is_power = n > 0 and (n & (n - 1)) == 0
41
+
42
+ ##########end上面可以改动
43
+ return is_power
44
+
45
+ if __name__ == "__main__":
46
+ ###########下面可以修改
47
+ print(TEST_DO_NOT_CHANGE(1))
48
+ print(TEST_DO_NOT_CHANGE(16))
49
+ print(TEST_DO_NOT_CHANGE(218))
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目
15
+ 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。
16
+
17
+ 示例:
18
+ 输入: 38
19
+ 输出: 2
20
+ 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2。 由于 2 是一位数,所以返回 2。
21
+ '''
22
+
23
+ # 参考答案
24
+
25
+ def TEST_DO_NOT_CHANGE(num):
26
+ result = None
27
+ ##########start下面可以改动
28
+ while num >= 10:
29
+ num_digit = len(str(num))
30
+ num_new = 0
31
+ i = 0
32
+
33
+ while i < num_digit:
34
+ num_new = num_new + int(str(num)[i])
35
+ i = i + 1
36
+
37
+ num = num_new
38
+
39
+ result = num
40
+ ##########end上面可以改动
41
+ return result
42
+
43
+ if __name__ == "__main__":
44
+ print(TEST_DO_NOT_CHANGE(38))
45
+ print(TEST_DO_NOT_CHANGE(1))
@@ -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 的数组,找到其中的多数元素。多数元素是指出现次数 超过一半(大于 ⌊n/2⌋,即 n 除以 2 向下取整)的元素。
16
+ 你可以假设数组是非空的,并且给定的数组总是存在多数元素。
17
+
18
+ 示例 1:
19
+
20
+ 输入: [3,2,3]
21
+ 输出: 3
22
+
23
+ 示例 2:
24
+
25
+ 输入: [2,2,1,1,1,2,2]
26
+ 输出: 2
27
+ '''
28
+
29
+ # 参考答案
30
+ def TEST_DO_NOT_CHANGE(nums):
31
+ res = 0
32
+ ##########start下面可以改动
33
+ i = 0
34
+ half = len(nums) // 2
35
+ nums_set = list(set(nums))
36
+
37
+ while i < len(nums_set):
38
+ if nums.count(nums_set[i]) > half:
39
+ res = nums_set[i]
40
+ break
41
+ else:
42
+ i = i + 1
43
+
44
+ ##########end上面可以改动
45
+ return res
46
+
47
+
48
+ if __name__ == '__main__':
49
+ print(TEST_DO_NOT_CHANGE([3,2,3]))
50
+ print(TEST_DO_NOT_CHANGE([2,2,1,1,1,2,2]))
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 实现一个函数计算 x 的整数 n 次幂,请不要直接用 ** 的方式(用循环自己实现)。
16
+ 考虑 n 为 负数、 正数、 0 等不同情况(提示:n 为负数时,结果是 1 除以 x 的 |n| 次幂)。
17
+ 如 x 为 3,n 为 2 时,result 返回值为:9。
18
+ 注:本题为进阶版;基础版(只考虑 n ≥ 0、实现方式不限)见 hwc120。
19
+ '''
20
+
21
+ # 参考答案
22
+
23
+ def TEST_DO_NOT_CHANGE(x,n):
24
+ result = None
25
+ ##########start下面可以改动
26
+ result = 1
27
+ i = 0
28
+ while i < abs(n):
29
+ result = result * x
30
+ i = i + 1
31
+
32
+ if n < 0:
33
+ result = 1 / result
34
+ ##########end上面可以改动
35
+ return result
36
+ if __name__ == "__main__":
37
+ ###########下面可以修改
38
+
39
+
40
+ print(TEST_DO_NOT_CHANGE(3,29))
41
+ print(TEST_DO_NOT_CHANGE(2,19))
42
+ print(TEST_DO_NOT_CHANGE(5,-2))
@@ -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
+ 给你一个按从小到大排好序的整数数组 nums(相邻元素允许相等,即"非递减"),
16
+ 返回每个数字的平方组成的新数组,要求也按从小到大排好。
17
+
18
+ 示例 1:
19
+
20
+ 输入: nums = [-4,-1,0,3,10]
21
+ 输出: [0,1,9,16,100]
22
+ 解释: 平方后,数组变为 [16,1,0,9,100] 排序后,数组变为 [0,1,9,16,100]
23
+
24
+ 示例 2:
25
+
26
+ 输入: nums = [-7,-3,2,3,11]
27
+ 输出: [4,9,9,49,121]
28
+ '''
29
+
30
+ # 参考答案
31
+ from typing import List
32
+ def TEST_DO_NOT_CHANGE(nums):
33
+ res = []
34
+ ##########start下面可以改动
35
+
36
+ for x in nums:
37
+ res.append(x**2)
38
+ res.sort()
39
+
40
+ ##########end上面可以改动
41
+ return res
42
+
43
+ if __name__ == "__main__":
44
+ ###########下面可以修改
45
+
46
+ print(TEST_DO_NOT_CHANGE([-4,-1,0,3,10]))
47
+ print(TEST_DO_NOT_CHANGE([-7,-3,2,3,11]))
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 求1+2!+3!+...+20!的和,保存到rlt_sum并返回。
16
+ '''
17
+
18
+ # 参考答案
19
+
20
+
21
+
22
+ def TEST_DO_NOT_CHANGE():
23
+ rlt_sum=None
24
+ ##########start下面可以改动
25
+ rlt_sum = 0
26
+ def factorial(n):
27
+ result = 1
28
+ for i in range(1, n + 1):
29
+ result *= i
30
+ return result
31
+
32
+ for i in range(1,21):
33
+ rlt_sum += factorial(i)
34
+
35
+
36
+ ##########end上面可以改动
37
+ return rlt_sum
38
+
39
+
40
+ if __name__ == "__main__":
41
+ ###########下面可以修改
42
+ print (TEST_DO_NOT_CHANGE())
@@ -0,0 +1,58 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 写一个程序,输出从 1 到 n 数字的字符串表示。
16
+
17
+ 规则:
18
+ 1.如果 n 是3的倍数,输出“Fizz”;
19
+ 2.如果 n 是5的倍数,输出“Buzz”;
20
+ 3.如果 n 同时是3和5的倍数,输出 “FizzBuzz”。
21
+
22
+ 示例 1:
23
+
24
+ 输入: n = 15
25
+ 输出: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
26
+
27
+ 示例 2:
28
+
29
+ 输入: n = 5
30
+ 输出: ['1', '2', 'Fizz', '4', 'Buzz']
31
+ '''
32
+
33
+ # 参考答案
34
+
35
+ def TEST_DO_NOT_CHANGE(n):
36
+ res = []
37
+ ##########start下面可以改动
38
+
39
+
40
+ for i in range(1, n + 1):
41
+ if i % 15 == 0:
42
+ res.append("FizzBuzz")
43
+ elif i % 3 == 0:
44
+ res.append("Fizz")
45
+ elif i % 5 == 0:
46
+ res.append("Buzz")
47
+ else:
48
+ res.append(str(i))
49
+
50
+
51
+ ##########end上面可以改动
52
+ return res
53
+
54
+ if __name__ == '__main__':
55
+ ###########下面可以修改
56
+
57
+ print(TEST_DO_NOT_CHANGE(15))
58
+ print(TEST_DO_NOT_CHANGE(5))
@@ -0,0 +1,58 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 给定一个整数,写一个函数来判断它是否是 3 的幂次方。如果是,返回 True ;否则,返回 False 。
16
+ 整数 n 是 3 的幂次方需满足:存在整数 x 使得 n == 3**x(即 1, 3, 9, 27, 81 ... 这类数)
17
+ 注意:0 和负数都不是 3 的幂次方,应返回 False。
18
+
19
+ 示例 1:
20
+
21
+ 输入: n = 27
22
+ 输出: True
23
+
24
+ 示例 2:
25
+
26
+ 输入: n = 0
27
+ 输出: False
28
+
29
+ 示例 3:
30
+
31
+ 输入: n = 9
32
+ 输出: True
33
+
34
+ 示例 4:
35
+
36
+ 输入: n = 1
37
+ 输出: True
38
+ '''
39
+
40
+ # 参考答案
41
+ from typing import List
42
+ def TEST_DO_NOT_CHANGE(n):
43
+ res=False
44
+ ##########start下面可以改动
45
+
46
+ while n > 1 and n % 3 == 0:
47
+ n //= 3
48
+ res = n == 1
49
+
50
+ ##########end上面可以改动
51
+ return res
52
+
53
+ if __name__ == "__main__":
54
+ ###########下面可以修改
55
+ print(TEST_DO_NOT_CHANGE(27))
56
+ print(TEST_DO_NOT_CHANGE(0))
57
+ print(TEST_DO_NOT_CHANGE(9))
58
+ print(TEST_DO_NOT_CHANGE(1))