# Python 簡單的程式 ## 整數加法 0. 假設我們有x 和 y , 我們要求x+y 1. 讀入x和y 2. 印出x和y 3. z = x+y 4. 印出z 5. 結束 ```python x = int(input("please input the value of variable x:")) y = int(input("please input the value of variable y:")) print("x value:",x) print("y value:",y) z = x+y print("z value:" ,z) ``` int 是指 integer(整數) input() 是指輸入, 也就是x要從鍵盤輸入, 輸入完成要按Enter鍵 **input()指令** 可以輸入資料,但是,這個資料都是字串, 比方說,你輸入2,Python語言並不知道這是數字2。 所以,我們要在input()前面加上int(),這樣就可以告訴Python, 我們輸入的是一個正整數。 我們稱為『轉型』,將『文字字串』轉為『整數數字』。 print() print("想要輸入的文字")。 print("x value:" ,x) 對於print指令而言, 他有兩個引數(argument) 一個"x value:", 另一個是x, 我們必須用 , 分開這兩個引數 ## 計算(x+y)/2 0. 假設我們有x和y, 我們要求(x+y)/2 1. 讀入x和y 2. 印出x和y 3. t = x+y 4. z = t/2 5. 印出 z 6. 結束 x = int(input("please input the value of variable x:")) y = int(input("please input the value of variable y:")) print("x value:",x) print("y value:",y) t = x+y z = t/2 print("z value:" ,z)