Python學習筆記:Day1-電腦、程式及Python概述 === [TOC] ## 學習目的 下個月6/12要去考APCS,剩24天,我打算把曾經學過的複習一遍,也記錄我學習的歷程,不管最後會不會拿到好成績,至少我學到的東西是不會消失的,而且畢竟學測在即,7/3號還要去考日語檢定,之後肯定會很忙,只能趁現在好好努力寫程式,為了以後的大學著想。所以我選了這本《Python程式設計入門指南》,根據我的學習進度,每天記錄一點,並統整筆記,重點是記錄我比較不熟的地方,在文末我會做答這本書提供的測驗題庫,測驗一下自己的學習成效,並記錄心得,希望我能持之以恆。 --- ## 電腦硬體組件 - **中央處理器** 又稱為CPU(Central Processing Unit) 接受來自記憶體的指令,並執行指令內容 運轉速度單位為赫茲(Hz) - **記憶體** 是一種儲存裝置 儲存容量單位為位元組(byte),1byte = 8bits | 名稱 | 容量(byte) | | ---- | ---- | | KB(kilobyte) | 1000 | | MB(megabyte) | 1百萬 | | GB(gigabyte) | 十億 | | TB(terabyte) |一兆 | 分為RAM(random-access memory)跟ROM(read-only memory) 1. RAM是隨機存取記憶體,具有依電性(volatile),電源關閉後記憶體的資訊便會消失,可以依據任何順序做存取,因此一般而言,RAM容量越大運轉的速度越快。 2. ROM是唯讀記憶體,不會因為電源關閉而資料消失,容量較大,但也無法隨意更改裏頭的資料。 - **儲存裝置** 磁碟(Magnetic disk drives) 光學硬碟(Optical disc drives) USB(Universal serial bus) - **輸入及輸出裝置** 鍵盤、滑鼠、螢幕等等 - **通訊裝置** 電腦可藉由通訊裝置網路化 速度單位bps,mbps ex:撥號數據機(modulator/demodulator)、數位用戶迴路(Digital Subscriber Line,DSL)、纜線數據機(cable modem) 網路介面卡(Network Interface Card,NIC)可將電腦連接到區域網路(Local Area Network),一般用於學校、公司行號等。 --- ## 程式語言 * **機器語言** machine language 最原始的指令,為二進位編碼(binary code) 不同型態的電腦有不同的機器語言 * **組合語言** assembly language 使用簡短的文字集合,稱為助憶符號(mnemonic) 需要組譯器(assembler)將組合語言翻譯成機器語言 接近機器語言,因此又被稱為低階語言(low-level language) * **高階語言** 語法與英文相似 以指令輔助撰寫程式,稱為敘述(statement) 原始碼(source code)須經轉翻譯成機器語言 翻譯工具可分為直譯器(interpreter)與編譯器(compiler) 直譯器:逐行翻譯並執行 編譯器:編譯後一次執行整個檔案 --- ## 作業系統 Operating System的主要功能如下 1. 控制和監控系統活動 2. 配置和指派系統資源 3. 排程的運作 關於排程,又分為**多元程式、多執行緒、多元處理**三種用途 **多元程式**(multiprogramming):多個軟體程式共享同個CPU,同時進行。 **多執行緒**(multithreading):單一程式同時間執行多個任務。 **多元處理**(multiprocessing):又稱作**平行處理**(parallel processing),兩個以上的處理器同時執行多個任務,再將結果合起來。 --- ## Python簡介 ### 特徵 簡單、簡潔、直覺式的語法 直譯器 物件導向(Object Oriented Programming,OOP) ### 特殊字元 | 字元 | 名稱 | 描述 | |:------- |:------ |:------------------ | | () | 小括號 | 使用於函式 | | # | 井字號 | 註解敘述的開頭字元 | | " " | 雙引號 | 字串 | | ''' ''' | 三引號 | 段落註解敘述 | ### 程式設計錯誤 1. 語法錯誤(syntax errors) 2. 執行期間的錯誤(runtime errors) 3. 邏輯錯誤(logic errors) --- ## 圖形程式設計簡介 在python裡,有多種的方式可撰寫圖形的程式,以下介紹一種模組來做為之後學習的例子。 turtle是python內建的圖形模組,用以畫線、圖形,以及其他形狀,包括文字。他易於學習與使用。 * 使用turtle模組 `import turtle` * 顯示文本 `turtle.write(string)` * 將筆往前移動 `turtle.forward(length)` * 設置筆顏色 `turtle.color("color")` * 移動筆到指定位置 `turtle.goto(x,y)` * 提起筆 `turtle.penup()` * 放下筆 `turtle.pendown()` * 畫圓 `turtle.circle(radius)` * 暫停程式畫面直到關閉 `turtle.done()` ### 實作-畫圈 ```python = #畫圈 import turtle turtle.color("blue") turtle.penup() turtle.goto(-110,-25) turtle.pendown() turtle.circle(45) #暫停程式畫面直到關閉 turtle.done() ``` --- ## 錯題訂正 ![chapter 1](https://i.imgur.com/EVHSqRq.jpg) 之後我每天都會在這個[測驗網址](http://liveexample.pearsoncmg.com/liang/py/test.html)測驗我的學習成效, 1.4 Why do computers use zeros and ones? A. because combinations of zeros and ones can represent any numbers and characters. ==B. because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.== C. because binary numbers are simplest. D. because binary numbers are the bases upon which all other number systems are built. ***因為0與1是電子設備的穩定態,所以電腦才會使用二進位制。*** 1.7 A computer's _______ is volatile; that is, any information stored in it is lost when the system's power is turned off. A. floppy disk B. hard disk C. flash stick D. CD-ROM ==E. memory== 1.9 ____________ is a device to connect a computer to a local area network (LAN). A. Regular modem B. DSL C. Cable modem ==D. NIC== 1.12 ___________ translates high-level language program into machine language program. A. An assembler ==B. A compiler== C. CPU D. The operating system 1.16 Which of the following statements is true? A. Python 3 is a newer version, but it is backward compatible with Python 2. ==B. Python 3 is a newer version, but it is not backward compatible with Python 2.== C. A Python 2 program can always run on a Python 3 interpreter. D. A Python 3 program can always run on a Python 2 interpreter. 1.17 ________ is an object-oriented programming language. ==A. Java== ==B. C++== C. C ==D. C#== ==E. Python== 1.20 To run python script file named t.py, use the command ________. A. execute python t.py B. run python t.py ==C. python t.py== D. go python t.py 1.25 A ___________ error does not cause the program to abort, but produces incorrect results. A. syntax B. runtime ==C. logic== ***邏輯錯誤會導致輸出結果錯誤,而不會導致程式停止。*** 1.30 To draw a circle with radius 50, use ___________. ==A. turtle.circle(50)== B. turtle.circle(100) C. turtle.drawcircle(50) D. turtle.drawCircle(50) 1.31 To lift the pen, use ___________. A. turtle.penUp() ==B. turtle.penup()== C. turtle.lift() D. turtle.up() 1.32 To put the pen down, use ___________. A. turtle.penDown() ==B. turtle.pendown()== C. turtle.putDown() D. turtle.down() ## 心得 今天光打這篇就花了將近五個小時,之後要控制一下時間才行,之後我的筆記會著重在比較不懂的地方,已經熟悉的地方就不多做詳述,冗長的詞句的地方改成條列式的關鍵字就好,這樣比較省時。今天學到了很多,主要是電腦硬體的分類,還有Python的環境設定,都是比較基礎的東西,但是細節很多,測驗的錯題也比我想像的還多,大多是粗心,雖然英文題目有些不習慣,不過可以練習英文也不錯啦,只希望我不要理解錯題目的意思就好。 ###### tags: `Python學習筆記`