林世鎧
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    # 程式設計(第24組) 14/03/2022 組長:黃凱葶 110251039 管院學士班學士班1年級 組員:林世鎧 110211052 經濟系學士班1年級 組員:周芃君 110211008 經濟系學士班1年級 組員:蘇家陞 110211033 經濟系學士班1年級 --- ## [Python列表 (Python Lists)](https://www.w3schools.com/python/python_lists.asp) * Python 編程語言中有四種集合數據類型: > `List`是一個有序、可變的集合。允許重複元素。 > `Tuple`是一個有序、不可變的集合。允許重複元素。 > `Set`是一個無序、不可變、無索引的集合。不允許重複元素。 > `Dictionary`是一個有序、可變的集合。不允許重複元素。 * 列表用於將多個元素存儲在單個變量中。 * 列表由方括號`[]`創建 * 搜索列表項時,第一項的編號為`0`,第二項的編號為`1`,以此類推。 * 負數編號意味著從列表末端開始,倒數第一項的編號為`-1`,倒數第二項的編號為`-2`,以此類推。 --- ### [Python - 訪問列表項 (Access List Items)](https://www.w3schools.com/python/python_lists_access.asp) * 切片:取得特定範圍的元素。如`[3:6]`,將搜索編號3~5的所有元素 > (如`[:6]`),將搜索最前項~編號5的所有元素 > (如`[3:]`),將搜索編號3~最末項的所有元素 * 新增 `lst.append()` * 刪除 `lst.remove()` * 清空 `lst.clear()` * 排序 `lst.sort()` * 總和 `sum()` * 項數 `len()` * 最大值 `max()` * 最小值 `min()` * 查找元素 `if "__" in` * 範例:查找`Hanoi`有無出現於列表中 ``` thislist = ["Beijing", "Hanoi", "Hong Kong", "Macau", "Seoul", "Taipei", "Tokyo", "Ulaanbaatar"] if "Hanoi" in thislist: print("Yes, 'Hanoi' is in the cities list") ``` --- Ex1: ``` lst = ["a","b","c","d","e"] lst[2] = "x" #將列表編號2的元素設為"x" lst.append("c") #於列表最後附加"c" lst.remove("b") #移除列表第一個"b" print(lst) ⇒ ['a', 'x', 'd', 'e', 'c'] ``` Ex2: ``` lst = ["a","b","c","d","e"] for i in lst: #針對lst中的每個元素i(即用i代表每個元素) print(i) ⇒ a b c d e ``` --- ## [Python for迴圈 (Python For Loops)](https://www.w3schools.com/python/python_for_loops.asp) * for迴圈:`for x in ___:` * for迴圈的內容需要縮排 * 利用for迴圈,我們將可以針對`List`、`Tuple`、`Set`等集合數據中的每個項目各執行一次。 * 除集合數據外,字符串同樣也是for迴圈的運用對象。 * 範例:走訪字符串中的字符 ``` for x in "Ryukyu": print(x) #記得要縮排! ⇒ R #大小寫照舊 y u k y u ``` --- ### 休息指令 (The break Statement) 若要停止for迴圈,使用`break`語句,即可在for迴圈走訪所有元素之前停止。 範例:在`x`為`"Euro"`時結束迴圈 ``` currencies = ["Dollar", "Euro", "Yen", "Pound"] for x in currencies: print(x) if x == "Euro": break ``` --- ### 繼續指令 (The continue Statement) 使用`continue`語句,可以直接結束for迴圈的當前走訪,並繼續下一個。 範例:不要印出`"Euro"` ``` currencies = ["Dollar", "Euro", "Yen", "Pound"] for x in currencies: if x == "Euro": continue print(x) ``` --- ### 範圍函數 (The `range()` Function) * 於`range()`函數框內輸入第一個參數,將獲得一個數字序列,起始值為0,遞增值為1,並以指定的參數結束。 * `range()`函數一般默認起始值為0,但是可以通過添加第二個參數來指定起始值 * `range()`函數一般默認遞增值為1,但是可以通過添加第三個參數來指定遞增值 範例: ``` for x in range(2, 23, 3): print(x) ``` --- ### for迴圈中的Else (Else in For Loop) `Else`可置於for迴圈之下,用於指定for迴圈結束後欲執行的指令。 範例: ``` for x in range(4, 9): print(x) else: print("Finally finished!") ``` --- ### 鑲嵌迴圈 (Nested Loops) 可在for迴圈裡嵌入另一個for迴圈,此時“內迴圈”將在“外迴圈”的每次走訪中執行一次。 範例: ``` adj = ["brown", "fragrant"] food = ["coffee", "toffee"] for x in adj: for y in food: print(x, y) ``` --- ### 跳過指令 (The pass Statement) 因為for迴圈的內容不能為空白,所以遇到空白內容的for迴圈時,放入`pass`語句以避免出錯。 範例: ``` for x in [0, 1, 2]: pass ``` --- Ex3: ``` #找出串中大於90000的元素 #換句話說,我需要去走訪串列 #換句話說,我需要:針對串列lst的每個元素x,找出大於90000的所有元素 lst = [60474,17966,96949,7521,93184,13290,80559,23407,32934,71592,53071] for x in lst: if x > 0 and x < 40000: print("第一組") print(x) elif x >40000 and x < 80000: print("第二組") print(x) elif x > 80000: print("第三組") print(x) ``` Ex4: ``` a = [1,3,2,5,4] b = 0 #總和 for x in a: print( "x=" ) print(x) b = +b+x print( "b=" ) print(b) print( "----------" ) print(b) ``` --- 開會記錄: 日期:2022年3月16日 開始時間:晚上9:00 結束時間:晚上9:50 内容:用for迴圈算出lst串列的總和,最大的值 ![](https://i.imgur.com/lr55VAS.jpg) --- ## 作業: 用for迴圈算出lst串列的總和 用for迴圈找出lst串列中最大的值 解答: [![](https://i.imgur.com/92X8jNK.png)](https://i.imgur.com/92X8jNK.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