Python 好好玩, 趣學電玩遊戲程式設計 Python Python BASIC Java JavaScript PHP C++ BASIC Python Python Python Xbox PlayStation Nintendo - 2 -
簡介 : 互動式 Python Shell : 編寫程式 Python File editor : 猜數字 : 腦筋急轉彎 : 龍域 ( ) : 使用 : 使用流程圖設計 遊戲 Hangman : 編寫 猜單字遊戲的程式碼 Chapter 7 : 擴充 猜單字遊戲 Python : 井字棋遊戲程式 OX tic-tac-toe - 3 -
Python 好好玩, 趣學電玩遊戲程式設計 : 推理遊戲 Bagels : 笛卡兒座標系統 : 聲納尋寶遊戲 : 凱撒密碼 ( ) : 黑白棋 : 黑白棋人工智慧模擬 Chapter15 AI : 繪製圖案 Python pygame : 動畫 pygame : 碰撞偵測 2D : 使用聲音和影像 : 使用了聲音和影像的 遊戲 17 20 Dodger - 4 -
1 Shell Python Shell 運算子 整數與浮點數 值 表示式 語法錯誤 把值儲存到變數中
Python 好好玩 - 趣學電玩遊戲程式設計 IDLE IDLE Python Shell Python Shell Shell >>> 2 + 2 Enter Return 1-1 Shell 4 1-1 Shell 2 + 2 + 2 4 1-1 Python 1-1 運算子 + - * / 運算 加法減法乘法除法 - * / Python - 12 -
第 1 章互動式 Shell Integers Ints 4 99 0 Floating-point numbers floats 3.5 42.1 5.0 Python 5 5.0 values Shell 2 2 + 2 expressions 1-2 運算子 值 2 + 2 值 表示式 1-2 Shell Enter >>> 2+2+2+2+2 10 >>> 8*6 48 >>> 10-5+6 11 >>> 2 + 2 4 2 + 2 Python Shell >>> - 13 -
Python 好好玩 - 趣學電玩遊戲程式設計 10 + 5 15 10 + 5 10 + 3 + 2 15 Python 1 + 2 * 3 + 4 11 13 2 * 3 (1 + 2 ) * (3 + 4) 21 (1 + 2) (3 + 4) 15 15 8 * 3 / 2 + 2 + 7-9 12.0 Shell Shell - 14 -
第 1 章互動式 Shell >>> 8 * 3 / 2 + 2 + 7-9 12.0 / 24 / 2 12.0 12.0 + 2 14.0 Shell 5 + Enter >>> 5 + SyntaxError: invalid syntax 5 + + 前與後 SyntaxError Python Shell >>> 變數 指定陳述句 assignment statement = Shell >>> spam = 15 >>> spam 15 1-3 - 15 -
Python 好好玩 - 趣學電玩遊戲程式設計 15 1-3 Enter Python >>> expressions 陳述句 statements Shell spam = 15 Enter spam = 10 + 5 spam = 10 + 7-2 15 15 spam 東西 stuff spam eggs bacon Python Shell Enter >>> spam = 15 >>> spam 15 spam spam 15 Shell - 16 -
第 1 章互動式 Shell >>> spam = 15 >>> spam + 5 20 15 spam spam + 5 15 + 5 spam + 5 Python NameError >>> spam = 15 >>> spma Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> spma NameError: name 'spma' is not defined spam spma Shell >>> spam = 15 >>> spam + 5 20 >>> spam = 3 >>> spam + 5 8 spam + 5 20 spam 15 spam = 3 15 3 spam 3 spam + 5 8 1-4 - 17 -
Python 好好玩 - 趣學電玩遊戲程式設計 3 15 1-4 spam 15 3 spam spam >>> spam = 15 >>> spam = spam + 5 20 spam = spam + 5 spam 5 spam spam 5 Shell >>> spam = 15 >>> spam = spam + 5 >>> spam = spam + 5 >>> spam = spam + 5 >>> spam 30 spam 15 spam + 5 spam 20 3 spam 30 eggs bacon - 18 -
第 1 章互動式 Shell >>> bacon = 10 >>> eggs = 15 bacon 10 eggs 15 1-5 15 10 1-5 bacon eggs spam = bacon + eggs Shell spam >>> bacon = 10 >>> eggs = 15 >>> spam = bacon + eggs >>> spam 25 spam 25 bacon eggs 10 + 15 spam 25 bacon + eggs spam = bacon + eggs 25 spam bacon eggs spam - 19 -
Python 好好玩 - 趣學電玩遊戲程式設計 Python Python 2 5 + - Python Python Python - 20 -
2 Python Hello World! 字串 字串的連接 資料型別 ( 如字串或整數型別 ) 使用 File Editor 來編寫程式
Python 好好玩 - 趣學電玩遊戲程式設計 在 IDLE 中儲存和執行程式 執行的流程 注釋 print() 函式 input() 函式 區分大小寫 Python 字串 strings ' Shell >>> spam = 'hello' Python Shell spam spam Python 'hello' >>> spam = 'hello' >>> spam 'hello' 'hello' 'Hi there!' 'KITTENS' '7 apples, 14 oranges, 3 lemons' 'Anything not pertaining to elephants is irrelephant.' 'A long time ago, in a galaxy far, far away...' 'O*&#wY%*&OCfsdYO*&gfC% YO*& % 3yc8r2' - 22 -
第 2 章編寫程式 + 字串連接 string concatenation Shell 'Hello' + 'World!' >>> 'Hello' + 'World!' 'HelloWorld!' 'HelloWorld!' >>> 'Hello ' + 'World!' 'Hello World!' + 資料型別 data type 'Hello' 5 Python + IDLE Shell IDLE File Editor Shell File New File 2-1 - 23 -
Python 好好玩 - 趣學電玩遊戲程式設計 2-1 Shell File Editor Shell >>> File Editor Hell World Hello World! 請確認您所安裝的是 Python 3 而不是 Python 2! File Editor 2-2 1 Ln: 1 0 Col: 0 2-2 File Editor - 24 -
第 2 章編寫程式 File Editor 原始程式碼 source code Python hello.py 1. # This program says hello and asks for my name. 2. print('hello world!') 3. print('what is your name?') 4. myname = input() 5. print('it is good to meet you, ' + myname) IDLE File Editor 2-3 2-3 File Editor IDLE File Save As Ctrl-S 2-4 hello.py 存檔 IDLE File Open hello.py 開啟舊檔 hello.py File Editor - 25 -
Python 好好玩 - 趣學電玩遊戲程式設計 2-4 File Editor Run Run Module F5 Shell Hello world! 2-5 2-5 hello.py Shell - 26 -
第 2 章編寫程式 Enter F5 https://inventwithpython.com/diff/#diff Compare 2-6 2-6 https://inventwithpython.com/diff/#diff NameError Python 2 Python 3 Hello world! What is your name? Albert Traceback (most recent call last): File "C:/Python26/test1.py", line 4, in <module> myname = input() File "<string>", line 1, in <module> NameError: name 'Albert' is not defined Python 3.4-27 -
Python 好好玩 - 趣學電玩遊戲程式設計 Python Python Python 執行 execution Python Hello World comment 1. # This program says hello and asks for my name. # Python Hello World 函式 function Python Python Hello World print() input() 函式呼叫 function call Python print() print() - 28 -
第 2 章編寫程式 print() Hello World 2 3 print() 2. print('hello world!') 3. print('what is your name?') 引數 argument 2 print() 'Hello world!' 3 print() 'What is your name?' 傳 passing Input() 4 input() myname 4. myname = input() input() 返回值 return value input() Albert input() 'Albert' 'Albert' myname Hello World print() 5. print('it is good to meet you, ' + myname) print() 'It is good to meet you, ' + myname Python - 29 -
Python 好好玩 - 趣學電玩遊戲程式設計 'Albert' myname print('it is good to meet you, ' + myname) print('it is good to meet you, ' + 'Albert') print('it is good to meet you, Albert') Python myname Hello world! What is your name? Carolyn It is good to meet you, Carolyn Hello world! What is your name? poop It is good to meet you, poop - 30 -
第 2 章編寫程式 myname abrahamlincoln name Python 1 東西 Stuff Shell spam eggs bacon spam SPAM Spam spam Python whatihadforbreakfastthismorning whatihadforbreakfastthismorning 駝峰式 (camel case) breakfast foodthismorning whatihadforbreakfastthismorning Python - 31 -
Python 好好玩 - 趣學電玩遊戲程式設計 input() print() + Python Python 3-32 -