CKSH-CSDC 4th
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 英打隨堂考! https://www.arealme.com/typing-test/zh/ ### 選擇[高頻單字]&[2分鐘] 接著點擊[開始]即可 ---- ## 學期末再考一次 ### 前三名(3+3)有獎歐~(社師請 #### 大家記得回去練練:D --- # 資料 ---- # 資料型態 ![image alt](https://cdn.discordapp.com/attachments/986084746578771978/1030118454797271181/unknown.png) ---- 確認資料型態 利用type()可以確認資料型態 ```python name = "Kevin" print(type(name)) ``` output ``` <class 'str'> ``` --- ## 整數interger(int) ```python property = 0 students = 27 debt = -10 ``` ---- # 浮點數float(float) ```python score = 0.3 sin= 0.7666 #簡單來說就是小數 ``` ---- ### 算術運算子 ---- | 運算子 | 意義 | 輸入 | 輸出 | |:----:|:------------:| ---- | ---- | | + | 加法 | 3+2 | 5 | | - | 減法 | 3-2 | 1 | | * | 乘法 | 3*2 | 6 | | / | 除法 | 3/2 | 1.5 | | // | 除法(取整數) | 3//2 | 1 | | % | 除法(取餘數) | 3%2 | 1 | | ** | 次方 | 3**2 | 9 | ---- ### 複合算術運算子 ---- ```python a=3 b=5 a+=b #a+b print(a) ``` ---- ```python! a=3 b=5 a+=b a=a+b ``` --- # 字串string(str) ```python name = "CKSH" food = "Hotdog" email = 'non'#使用''亦可 ``` ---- ## 字串的運算 ---- 字串相連接 ```python word = "Genshin" feed = "turn on" output = word+feed #print(word+feed) print(output) ``` ---- 字串乘法 ```python word ="Genshin" output = word*3 #print(word*3) print(output) ``` ---- ## 索引(Index) 用[]取元素 ---- ```Python S="Hello,world!"#第一個字是從0開始數 print(S[1:4])#ell print(S[-5:-2])#orl print(S[1])#e print(S[6:])#world! ``` ---- 假設我想從friend提取出fiend並且輸出,程式碼該怎麼打(5分鐘) ---- ```py word = 'friends' devil = word[0] + word[2:4] + word[-3:-1] #print(word[0]) #print(word[2:4]) #print(word[-3:1]) print(devil) ``` ``` fiend ``` ---- ## .format() ---- ### 填充題 ``` Remember me to one _(A)_ lives there, she once was a true love of _(B)_. ``` (A) _who_ (B) _mine_ ---- ```python! #第一種,直接按照順序將參數填入空格: print('Remember me to one {} lives there, she once was a true love of {}.'.format('who','mine')) #第二種,在大括號中指定參數名稱(關鍵字參數) print('Remember me to one {p} lives there, she once was a true love of {v}.'.format(p = 'who',v = 'mine')) #第三種,在大括號中指定參數的索引值(index) print('Remember me to one {0} lives there, she once was a true love of {1}.' .format('who','mine')) ``` ---- ## 有什麼好處? ---- ### 如果不使用 ```python UserName="Smarsh" UserID="123456789" Server="CSDC4TH" joinTime= "2077/01/01 21:35" print(UserName,'is welcome to',Server,'at',joinTime,'ID:',UserID ) ``` ---- ```python UserName="Smarsh" UserID="123456789" Server="CSDC4TH" joinTime= "2077/01/01 21:35" print('{} is welcome to {} at {},ID:{}' .format(UserName,Server,joinTime,UserID)) ``` --- # 布林值(bool) ### A.K.A對或錯 ```python 社長是子腸 = False 社長是子暘 = True 福利社不會漲價 = False 校長家很大 = True ``` ---- ## 選擇性敘述 ---- ## 敘述 ![](https://hackmd.io/_uploads/rytAsKAGT.png) ![](https://hackmd.io/_uploads/B1Sm-MkQp.png) ---- ##### 過多的if反而會造成邏輯判斷的混淆,拖累執行的速度 ---- ### 巢狀if ---- ![](https://i.imgur.com/jnGnkHU.png) ---- ### 判斷三角形的類型(5分鐘) ``` 輸入三線段長度,判斷是否構成三角形, 且是鈍角、直角﹑還是銳角三角形 ``` 提示 ``` 若a、b、c為三個線段的邊長,且c為最大值,則 若 a+b ≦ c,三線段無法構成三角形 若 a×a+b×b < c×c,三線段構成鈍角三角形(Obtuse triangle) 若 a×a+b×b = c×c,,三線段構成直角三角形(Right triangle) 若 a×a+b×b > c×c,三線段構成銳角三角形(Acute triangle) ``` ---- ```python a=input("輸入邊長1:") b=input("輸入邊長2:") c=input("輸入邊長3:") ``` ### 那怎麼比較大小? ---- ```python max=0 if a>max: max=a if b>max: max=b if c>max: max=c ``` --- # list ---- ## 宣告方式 : [逗點分隔的清單] ```python! nums = [1, 2, 3.0, '4'] # 不一定要相同型別 arr = [] # 也可以是空的 list ``` ---- ## 取得 list 的元素 ```python! # 0, 1, 2, 3 # -4, -3, -2, -1 nums = [ 1, 5, 2, 3] print(nums[0]) # 1 print(nums[2]) # 2 print(nums[-1]) # 3 print(nums[-2]) # 2 ``` ---- ## 新增元素到 list 結尾 ```python! nums = [1, 5, 2, 3] nums.append(5) print(nums) # [1, 1, 2, 3, 5] ``` ---- ## 練習(3分鐘) 輸入一個 list,再把他 print 出來。 ```python n = int(input('請輸入 list 的長度:')) # 提示:迴圈 + 一個個 append ``` 期望執行結果: ``` 請輸入 list 的長度:3 4 5 6 [4, 5, 6] ``` ---- ### 參考解答- ```python n = int(input('請輸入 list 的長度:')) arr = [] for i in range(n): inp = int(input()) arr.append(inp) print(arr) ``` ---- ## 取得 list 的長度:len() ```python arr = [] len(arr) # 0 arr = [2, 4, 6] len(arr) # 3 ``` ---- ## list 大小排列:list.sort() & sorted() ---- ```python arr = [9,8,5,2,7,4,6,3,1,0] arr.sort() print(arr) # 0 1 2 3 4 5 6 7 8 9 arr.sort(reverse=True) print(arr) # 9 8 7 6 5 4 3 2 1 0 ``` ---- <iframe width="100%" height="500" src="https://shengyu7697.github.io/python-sort/" frameborder="0"></iframe> [點擊前往](https://shengyu7697.github.io/python-sort/) ---- ### 判斷三角形(5分鐘) ---- ```python arr = [] for i in range(3): inp = int(input()) arr.append(inp) n.sort() a = n[0] b = n[1] c = n[2] l = a * a + b * b r = c * c print(a, b, c) if a + b <= c: print('無法構成三角形') elif l < r: print('銳角三角形') elif l == r: print('直角三角形') elif l > r: print('鈍角三角形') ``` --- ## 我上次教太快了 ### 所以我再補充一下迴圈的內容 ---- ## while 的用法 #### 這裡就先自己看看 ---- ``` 迴圈是一種控制結構,允許程式在一個或多個條件成立的情況下重複執行一段程式碼,直到特定的條件不再成立。迴圈的主要目的是減少重複性的工作,讓程式可以有效處理大量相似的任務。 狀況使用迴圈的例子包括: 1. 處理列表或陣列:當你需要依次處理列表或陣列中的每個元素時,使用迴圈可以讓你一一訪問並處理它們。 2. 輸入驗證:當你需要持續驗證使用者的輸入,直到它符合特定條件,例如輸入正確的密碼。 3. 重複性任務:當你必須執行相同的操作多次,例如列印特定模式的星號或數字。 4. 檢查條件:當你需要重複檢查某個條件,直到該條件不再成立,例如等待某個事件發生。 5. 資料處理:當你需要處理大量資料或執行一系列操作,以檢查、轉換或過濾資料。 ``` ---- ## 他的用法就是 ``` python while 條件: # 迴圈內的程式碼 ``` ---- #### 說明 ``` while 是 Python 中的關鍵字,用來標示開始一個 while 迴圈。 條件 是一個布林表達式,它決定是否繼續執行迴圈。只要這個條件為真(True),迴圈就會持續執行。 迴圈內的程式碼位於冒號(:)之後,並使用縮排(通常是四個空格)來表示它們屬於迴圈的內容。 當 條件 為真時,迴圈內的程式碼將被執行,然後再次檢查 條件。這個過程將一直重複,直到 條件 變為假(False),此時迴圈停止執行,程式流程繼續向下。 ``` ---- ## 舉個例子 #### 我要如何使用while來印出數字 1 到 5 #### 那麼就可以這樣寫 ``` python count = 1 while count <= 5: print(count) count += 1 ``` ``` 這裡的 count += 1 代表 count=count+1 當 count 變數小於或等於 5 時 print(count) 會被執行 然後 count 會遞增 當 count 變成 6 時 條件變為假,迴圈停止執行。 ``` --- ## 接下來來講 for i in range #### 文字說明(一樣自己看看:) ) ``` 當你教導 Python 的迴圈 for 時,通常會使用它來重複執行一組程式碼,並對不同的元素或項目進行操作。 1.迭代列表、元組、字典、字串等容器中的元素。 2.執行固定次數的迭代,比如從 1 到 N。 3.在特定範圍內迭代,例如在一個區間內。 ``` ---- ### 有人不懂迭代嗎? ![image.png](https://hackmd.io/_uploads/S1MRs2JQp.png) ---- ### range 的用法 ``` 在Python中,range是一個用於產生一系列整數的函數。它通常用於循環和迭代操作,允許你指定一個起始值、一個結束值和一個可選的步長來產生一系列整數。 ``` #### range函數的語法一般如下: ```python! range([start], stop, [step]) ``` ``` start是可選的,表示範圍的初始值,預設為0。 stop是必需的,表示範圍的結束值(不包含在範圍內)。 step是任選的,表示範圍中相鄰兩個整數之間的步長(預設為1)。 range函數傳回一個包含從start到stop之間的整數序列,按照指定的步長遞增。該序列通常用於for循環中,用於迭代處理一系列整數。 ``` ---- ### 以下是一些範例: ```python! # 生成整数序列 [0, 1, 2, 3, 4] for i in range(5): print(i) # 生成整数序列 [2, 4, 6, 8] for i in range(2, 10, 2): print(i) # 生成整数序列 [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] for i in range(10, 0, -1): print(i) ``` #### 大家可以自行練習一下 (2 min ---- ![image.png](https://hackmd.io/_uploads/rJ0hMTk7a.png) --- ### 接下來有一些小題目讓大家練習 #### 這些題目都可以用while 或for i in range 解 ---- ### 問題1:計算 1 到 10 的總和。 (2min) ---- ##### for i in range 的解法 ```python! total = 0 for i in range(1, 11): total += i print(total) ``` ##### while 的解法 ```python! total = 0 i = 1 while i <= 10: total += i i += 1 print(total) ``` ---- ### 問題2:列印 1 到 10 的平方。 (2min) ---- ##### for i in range 的解法 ```py! for i in range(1, 11): print(i ** 2) ``` ##### while 的解法 ```py! i = 1 while i <= 10: print(i ** 2) i += 1 ``` ---- ### 問題3:列印 1 到 100 中的所有偶數。 (2min) ---- ##### for i in range 的解法 ```py! for i in range(2, 101, 2): print(i) ``` ##### while 的解法 ```py! i = 2 while i <= 100: print(i) i += 2 ``` ---- ### 問題4:計算 5 的階乘。 (2min) #### 階乘還沒忘吧 ![image.png](https://hackmd.io/_uploads/HkKmJakXp.png) ---- ##### for i in range 的解法 ```py! factorial = 1 for i in range(1, 6): factorial *= i print(factorial) ``` ##### while 的解法 ```py! factorial = 1 i = 1 while i <= 5: factorial *= i i += 1 print(factorial) ``` ---- ### 問題5:列印 10 到 1 的倒數。 (3min) ---- ##### for i in range 的解法 ```py! for i in range(10, 0, -1): fraction = 1 / i print(fraction) ``` ##### while 的解法 ```py! i = 10 while i >= 1: print(1/i) i -= 1 ``` ---- ![image.png](https://hackmd.io/_uploads/ByNreJema.png) ---- ## 難度提高囉 :) ### 問題6:求1到100之間所有質數。 ##### 質數是指只能被1和自身整除的正整數。 (4min) ---- ```py! for num in range(2, 101): is_prime = True for i in range(2, int(num ** 0.5) + 1): if num % i == 0: is_prime = False break if is_prime: print(num) ``` ---- ![image.png](https://hackmd.io/_uploads/HkRUWklma.png) ---- ### 問題7:計算1到100之間所有質數的平方和。 (5min) ---- ```py! prime_sum_of_squares = 0 for i in range(2, 101): is_prime = True if i <= 1: is_prime = False for j in range(2, int(i**0.5) + 1): if i % j == 0: is_prime = False break if is_prime: prime_sum_of_squares += i**2 print(prime_sum_of_squares) ``` ---- ### 好啦 最後一題了 ### 問題8:計算1到100之間所有質數的平方和,找出這個平方和的因數。 #### 這題很難 自己想想吧 ---- ![image.png](https://hackmd.io/_uploads/Hyaol6kmT.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully