--- tags: computer science --- <center> # **APCS Python 101** ![](https://i.imgur.com/pfQzsI4.png =100x) </center> <p style="text-align: right"> "Either run for food, or run from being food."<br>-- Jen-Hsun "Jensen" Huang (1963-),<br>the co-founder of <a href = "(https://www.nvidia.com/">NVIDIA</a> </p> <p style="text-align: right"> ``Programming is not about typing,<br>it's about thinking.''<br>-- Rich Hickey </p> <p style="text-align: right"> "You don't have to be great to start,<br>but you have to start to be great."<br>-- Zig Ziglar </p> ## 課程訊息 <img src = "https://i.imgur.com/yhCgh7Y.jpg" height = 150px style="float:right"/> ### 講者訊息 - 盧政良 (Zheng-Liang Lu, Arthur) - 電子信箱:arthurzllu@gmail.com ### 工作環境 - 免安裝軟體的方案:[Google Colab](https://colab.research.google.com/) - 若沒有 Google 帳號,請先自行申請一個 [Gmail](https://www.google.com/intl/zh-TW_tw/gmail/about/);填寫資料時,務必輸入一個出生年使目前年齡可以超過 18 歲。 - 需要安裝軟體的方案 - [Python 3.10](https://www.python.org/downloads/) - 編輯環境:[Visual Studio Code](https://code.visualstudio.com/), [Spyder](https://www.spyder-ide.org/), or [PyCharm](https://www.jetbrains.com/pycharm/)<img src = "https://hackmd.io/_uploads/S1ucxUROq.png" height = 250px style="float:right"/> ### 預備知識 - 四則運算、代數運算 - 中學數學 - 有[多項式 (polynomial)](https://zh.wikipedia.org/zh-tw/%E5%A4%9A%E9%A0%85%E5%BC%8F) 與[對數 (logarithm)](https://zh.wikipedia.org/zh-tw/%E5%AF%B9%E6%95%B0) 經驗者佳。 - 對於需要考 APCS 檢定的學員,請務必提前了解[資訊科學的高中數學](https://hackmd.io/@arthurzllu/r1yS6hxqc)。 - 由於 APCS 考試中觀念題以 C 語言出題,故在應考前務必了解 [APCS 考試指定程式語言對照表](https://hackmd.io/@arthurzllu/HJEpmDdt2) 與 [APCS C++ 大學程式能力檢定考前衝刺](https://hackmd.io/@arthurzllu/Bkc2ujCc3)。 ### 學習目標 - 掌握 Python 基本語法。 - 學習以流程 (演算法) 為基礎的程式設計概念。 - 了解電腦運作原理與利用電腦解決問題。 - 培養對科技的興趣並建立<font color = "red">自我學習</font>的能力。 - 建立基礎後可進一步學習其他程式語言,如:[APCS 大學程式設計 C++ 基礎班](https://www.csie.ntu.edu.tw/~d00922011/cpp.html)、[Java 基礎程式設計班](https://www.csie.ntu.edu.tw/~d00922011/java.html)、[C# 程式設計基礎班](https://www.csie.ntu.edu.tw/~d00922011/csharp.html)。 - 亦可銜接資訊領域內的進階課程,如:[演算法實戰班](/lEtjPRBFQUSTAFB8FTylXA)、[資料科學入門](/gYLiNF6PQkqiW3QRMzA8CA)、[Python 財務計算](/RjzdJKGGSDGTozfU_W_hlQ)、[財務計算專題:期貨與選擇權](https://hackmd.io/@arthurzllu/SJLG2r8U5)等應用課程。 ### 電子郵件通訊禮節 - 電子郵件的標題 (Title) 需要註明**班別**與**中文姓名**,並加上**信件主旨**,如:Python 403 金城武 作業繳交。 - 利用電子郵件提問時,務必提供完整的訊息,諸如:問題敘述、曾經嘗試但是失敗的方案、可能的猜想等等。任何有助於了解問題的材料皆可附上,如程式碼、錯誤訊息的截圖。 ### 評分標準 & 結業證書領取 - 本課程有<font color = "red">五次</font>的程式作業,於特定的章節內公布並在繳交期限當日進行檢討;完成五次程式作業的學員可獲頒證書。若有調整,以調整後的政策為主。 - 領取證書的細節詳見[訓練班公告網頁](https://train.csie.ntu.edu.tw/train/certificate.php)。 ### 課程錄影 - 本課程除非經授課老師同意,學生不得擅自進行課程錄音錄影。 - 若因無法出席而缺課或需要課後複習的學員,可自行前往 [NTU COOL](https://cool.ntu.edu.tw/) 進行補課。該網站的帳號密碼為學員在訓練班報名時登錄的帳號密碼。 - 課程影片將會在課程結束後一週下架,需要複習的學員務必注意時程。 <img src = "https://i.imgur.com/N3rHh8o.jpg" height = 300px style="float:right"/> ## 課程架構 ### 第零回:導論 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_0_introduction.ipynb)</font> - 課程要求 - 背景知識 - 電腦如何運作? <font size = -1>[link](http://ed.ted.com/lessons/inside-your-computer-bettina-bair)</font> - 資料如何保存? <font size = -1>[link](http://ed.ted.com/lessons/how-computer-memory-works-kanawat-senanan)</font> - 什麼是演算法? <font size = -1>[link](http://ed.ted.com/lessons/your-brain-can-solve-algorithms-david-j-malan)</font> - Python 基本操作說明 - 輸出輸入 - 變數的使用 - 字串的使用 - 引用模組 - 除錯 ### 第一回:變數、資料型態、運算子 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_1_variable_type_operator.ipynb)</font> - 二進位系統 - 變數的使用與記憶體位址的概念 - 資料型態:整數、浮點數、字串、布爾值 - 指定運算子與記憶體模型 - 算術運算子、關係運算子 ### 第二回:資料結構 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_2_data_structures.ipynb)</font> - 清單 (list) - Tuple - 集合 (set) - 字典 (dictionary) - 進階概念:記憶體配置 - 為什麼 list 與多數資料結構的第一個元素從 <font color = "red">0</font> 開始? - 淺拷貝 (shallow copy) 與深拷貝 (deep copy) - 破壞性操作與非破壞性操作 ### 第三回:流程控制 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_3_flow_controls.ipynb)</font> - 有條件的敘述 - 重複的敘述 - for 迴圈與 while 迴圈 - 多層迴圈 - Comprehension <!-- ### 週末作業檢討 <font size = -1>[colab link](https://colab.research.google.com/drive/1kKeV6wOavNWTkQOno1lNGBoiomvl8N9I?usp=sharing)</font> --> ### 第四回:函式 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_4_functions.ipynb)</font> - 定義新的函式 - 匿名函式:lambda - 函式設計風格:map & filter - 函式與記憶體堆疊 (stack) - 區域變數 (local variable) 與全域變數 (global variable) - 視覺化 http://www.pythontutor.com/visualize.html - 遞迴 (recursion) <center> ![](https://i.imgur.com/rKVSmtE.png =600x) </center> ### 第五回:演算法 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_5_algorithms.ipynb)</font> - 排序演算法 - 演算法分析 - 對數時間演算法 <font size = -1>[pdf](https://www.csie.ntu.edu.tw/~d00922011/java/log-time_algorithm.pdf)</font> - 更多資訊請參考 [Analysis of Algorithms](https://algs4.cs.princeton.edu/lectures/keynote/14AnalysisOfAlgorithms.pdf) - 搜尋演算法 - 洗牌演算法 - 蒙地卡羅法 - 動態規劃 - [LeetCode](https://leetcode.com/problemset/): 邁向軟體工程師之路 ### 第六回:例外處理與檔案處理 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_6_exception_and_files.ipynb)</font> - 例外處理:try-except-else-finally - 自定義例外 - 檔案處理 ### 第 X 回:專題討論 - Python 視覺化工具 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_x_graphics.ipynb)</font> - Python Pandas: 資料科學的第一步 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_x_pandas.ipynb)</font> - Python 爬蟲範例:以 Ptt Web 為例 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_x_ptt_crawler_demo.ipynb)</font> - Take home message: https://www.csie.ntu.edu.tw/~d00922011/cpp/takehome_msg.pdf ### 第七回:物件導向設計 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_7_oop.ipynb)</font> - 類別與物件 - 封裝、繼承、多型 - 模組與套件 ### 第八回:進階議題 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_8_advanced_topics.ipynb)</font> - 私有成員 - Magic Methods - 靜態成員 - 修飾子 - 產生器與迭代器 - 平行程式 <font color = "red" size = -1>new</font> <!-- ### 第九回:資料視覺化 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_9_pandas_matplotlib_seaborn.ipynb)</font> - 資料處理的救星:Pandas - 繪圖套件:Matplotlib, Seaborn ### 第十回:科學計算初探 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_10_numpy_scipy.ipynb)</font> - 線性代數套件:NumPy - 科學計算套件:SciPy --> ### 第九回:資料視覺化 <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_9_pandas_matplotlib_seaborn.ipynb)</font> - 資料處理的救星:[Pandas](https://pandas.pydata.org/) - 繪圖套件:[Matplotlib](https://matplotlib.org/), [Turtle](https://docs.python.org/3/library/turtle.html) ### 最終回:Game of Life <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_11_game_of_life.ipynb)</font> <center> ![](https://i.imgur.com/itJDrX5.gif) </center> <!-- ### 番外篇:APCS 檢定考試解題 ### 實戰篇:APCS 檢定考試題庫 --> <!-- ### Python for Excel <font size = -1>[notebook](https://www.csie.ntu.edu.tw/~d00922011/python/101/notebooks/py_x_python_and_excel.ipynb)</font> - 參考書目 - Felix Zumstein, [Python for Excel: A Modern Environment for Automation and Data Analysis](https://www.oreilly.com/library/view/python-for-excel/9781492080992/), 2021 <font size = -1>[github](https://github.com/fzumstein/python-for-exel)</font> ![](https://hackmd.io/_uploads/ryGUfS5Lq.png =100x) ### Python 網路應用:爬蟲 --> ## 點名單暨成績簿 <iframe src = "https://docs.google.com/spreadsheets/d/e/2PACX-1vTD5H34fdBECq42ZPUpFcMBcW2EVAGM92CqnG31_5ELGXLMsWO-yHtdTzpEJybFhzcfizPBv7OxYBwB/pubhtml?gid=1864969416&amp;single=true&amp;widget=true&amp;headers=false" width = 700 height = 900></iframe> ## 參考文獻 ### 使用文件 - Python: https://docs.python.org/3/tutorial/index.html - https://www.python.org/dev/peps/pep-0008/ - Pandas: https://pandas.pydata.org/ - Matplotlib: https://matplotlib.org/ - Seaborn: https://seaborn.pydata.org/ - Plotly: https://plotly.com/api/ - NumPy: https://numpy.org/ - SciPy: https://www.scipy.org/ - PEP8: https://www.python.org/dev/peps/pep-0008/ ### 大學課程 - [CMU 15-112: Fundamentals of Programming and Computer Science](https://www.cs.cmu.edu/~112/index.html), Carnegie Mellon University <font size = -1 color = "red">IN PROGRESS</font> - [CS41 happy code the python programming language](https://stanfordpython.com/), Stanford University <font size = -1 color = "red">IN PROGRESS</font> - [Python Practice](http://python.berkeley.edu/resources/), University of California, Berkeley <font size = -1 color = "red">IN PROGRESS</font> - [CS 61A: Structure and Interpretation of Computer Programs](https://cs61a.org/), University of California, Berkeley <font size = -1 color = "red">IN PROGRESS</font> - [Scientific Programming in Python](http://ucl-cs-grad.github.io/scipython/lectures.html) - CS50, [Large Language Models and The End of Programming - Tech Talk with Dr. Matt Welsh](https://www.youtube.com/watch?v=JhCl-GeT4jw), Harvard University, 2023.10.30 <font size = -1 color = "red">ENLIGHTENING</font> ### 免費教學平台/題庫 - 科技領域加深加廣選修課程之進階程式設計 [link](https://ghresource.mt.ntnu.edu.tw/nss/p/InformationTechnologyTPD05) - APCS 大學程式設計先修檢測:https://apcs.csie.ntnu.edu.tw/ - 考試環境說明:https://apcs.csie.ntnu.edu.tw/index.php/info/environment - 吳邦一 (Bangye Wu), [FB社團:APCS實作題檢測](https://www.facebook.com/groups/359446638362710) - 高中生程式解題系統:https://zerojudge.tw/ - LeetCode: https://leetcode.com/ - CodeWars: https://www.codewars.com/ - Kaggle: https://www.kaggle.com/learn/python ### 可以參考的書籍 - Irv Kalb, [Learn to Program with Python 3](https://link.springer.com/book/10.1007/978-1-4842-3879-0), 2018 <font color = "gray" size = -1>你可以透過在教室裡的電腦進行下載。</font> ![](https://hackmd.io/_uploads/S1rHYSZac.png =100x) ### 跟課堂有關的電影/影集 - [Imitation Game (2014)](https://www.imdb.com/title/tt2084970/) ![](https://i.imgur.com/Dn7BZQw.png) - [DeepMind: AlphaGo (2017)](https://www.imdb.com/title/tt6700846/) ![](https://i.imgur.com/MpD9mIn.png) - New Mind, [Computing Technology](https://youtube.com/playlist?list=PLC7a8fNahjQ8IkiD5f7blIYrro9oeIfJU), 2023 ![](https://hackmd.io/_uploads/Bysx9mNhi.png =300x) ### 與程式設計相關的遊戲 - [Human Resource Machine](https://store.steampowered.com/app/375820/Human_Resource_Machine/) ![](https://i.imgur.com/gqgb1IJ.png =300x) - [7 Billion Humans](https://store.steampowered.com/app/792100/7_Billion_Humans/) ![](https://i.imgur.com/6Tf8t0k.png =300x) - [Turing Complete](https://store.steampowered.com/app/1444480/Turing_Complete/) ![](https://hackmd.io/_uploads/S1x_po6LF.png =300x) - [while True: learn()](https://store.steampowered.com/app/619150/while_True_learn/) ![](https://hackmd.io/_uploads/SJfbTgjhc.png =300x) - [A=B](https://store.steampowered.com/app/1720850/AB/) ![](https://hackmd.io/_uploads/HyKahgj39.png =300x) - [Virtual Circuit Board](https://store.steampowered.com/app/1885690/Virtual_Circuit_Board/) ![](https://hackmd.io/_uploads/ryMTalj3q.png =300x) ### 不分類 - [A brief history of Python](https://exyte.com/blog/a-brief-history-of-python) - 让水烧开, [編程語言到底是如何演化至今的,你知道嗎?【編程語言發展史】](https://www.youtube.com/watch?v=A4gelx7IHlY), 2024.1.2 <center> ![](https://i.imgur.com/PWKtSDg.png =400x) </center>