# 入門Python ## 教學簡報 ![](https://hackmd.io/_uploads/SysZ_iZl6.gif) 1. --- # 事前準備 ``` 1.開啟Visual Studio Code 2.點選左上角File > Open Folder... 3.新建資料夾並點選 4.按下大大的藍色按鈕 5.新建檔案(檔案名稱.py) ``` --- # 輸入&輸出 ---- # 輸入 ---- # 來講些什麼呢? ---- ## 我想和老師拿題目 ##### 我會說:[老師我需要__份題目] ##### 老師會回應:[你需要幾份題目?] ##### 那麼我就要回應__ ---- ## python的寫法就是 ```python! a = input ("你需要幾份題目?") ``` ---- # 輸出 ---- 來講些什麼吧~ ---- ```python x = 1 print(x) #x是整數 print("你為甚麼不問問神奇海螺呢?") ``` output ``` 1 你為甚麼不問問神奇海螺呢? ``` ---- ![](https://hackmd.io/_uploads/r1dCasbgT.png) 我也那麼覺得 ---- # print的基本構造 ---- ```python print(變數) print("字串") print(變數+變數) print("字串"+變數) print("字串","字串") print("字串",變數) ### 關於變數,我們會再做一期講解 ... ``` ---- ![image alt](https://img.ttshow.tw/images/author/shelley/FotoJet(986).jpg)] ---- ## 輸入加輸出的經典題目就是 ### hello world #### 但我們稍稍改一下 ---- ```python! a = input ("你的名字是?") print ("Hello",a) ``` --- # 基本運算 ## 主要就是加減乘除:) ---- ```python a = 21 b = 10 c = a + b print ( " a + c 的值為:" , c ) c = a - b print ( " a - c 的值為:" , c ) c = a * b print ( " a * c 的值為:" , c ) c = a / b print ( " a / c 的值為:" , c ) ``` ---- # 總是有特別的算式:) ## 去掉小數aka無條件捨去 ```python a = 21 b = 10 c = a // b print ("a / c 的值約為:", c) ``` ---- ## 平方 ```python a = 2 b = 3 c = a ** b print ("a的b次方為:", c) ``` ---- ## 牛刀小試 ### >>買一段時間需要花費多少錢? ---- ```python time = input ("How much time do you want to buy:") money = int(input("How much is it:")) #以下示範三種寫法 print("To buy "+time+" you need " + str(money) + " dollars" ) #遇到變數記得用+來隔開 print("To buy",time,"you need",money,"dollars") #用逗點會自動加入一格空白建 print(f"To buy {time} you need {money} dollars") #f-string在最前面加f並給變數中括號也可以達到同樣的效果 ``` --- ### 題一 ``` 題目: 老師要登記大家的資料,能幫老師用程式做一串問題嗎,題目要有姓名、歲數、電話。 PS:共三個問題,依次詢問 ``` ---- ### 解 ---- ```python! name = str(input("what is your name")) age= int(input("What is your age")) number = int(input("What is your phone number")) print("name:",name) print("age:",age) print("phone number:",number) ``` ---- ### 題二 ``` 題目: 有一個四角柱長xcm寬ycm高zcm 請幫我寫出一個通用的算式 當我給出x y z時 能幫我算出體積 請大家用剛剛所教的寫看看 ``` ---- ### 解 ---- ```python! x = int(input()) y = int(input()) z = int(input()) print("此四角柱的體積是",(x*y*z),"立方公分") ``` ---- ### 題三 ##### 這題稍稍進階一點,想說有人有先學過,可以試試 ``` 題目: 請輸出一個整數,代表正值國喜歡的數字 但是,這個國家有一個不成文的習俗,就是他們不喜歡負數,他們把負數視為邪惡的象徵,所以他們非常討厭看到負數。他們只要看到負數,就會直接把負號去掉,例如”-1”會變成”1”。 ``` ---- ### 解 ---- ```python! x= int(input()) if x<0 : print((-1)*(x)) else : print(x) ``` --- # 今天就教到這,要記得複習喔!
{"contributors":"[{\"id\":\"35a0644c-29d6-4dd3-98eb-9df68421a475\",\"add\":4497,\"del\":3039},{\"id\":\"3963913a-1955-4863-b231-e15edfb3078e\",\"add\":1143,\"del\":134}]","title":"變數&基本輸入輸出","description":"title:變數與基本運算"}
    329 views
   Owned this note