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
    --- title: 條件式&迴圈 tags: 教學簡報 --- # 複習一下吧 ---- ## 同向追趕問題 ---- ### 試著用你所學實現以下內容 ```python #時速單位:Km/hr,距離單位:m 輸入甲車時速=80 輸入乙車時速=20 輸入甲乙距離=100 甲追到乙所需時間:6.0s ``` ---- ```python Acar = float(input("輸入甲車時速")) Bcar = float(input("輸入乙車時速")) x = float(input("輸入甲乙距離")) delta = (Acar-Bcar)/60/60*1000 time = float(x/delta) print("甲追到乙所需時間:"+str(time)+"s") ``` ---- 但如果甲車比乙車慢怎麼辦.. --- # 條件式敘述 新的工具~ ---- ## if-流程圖(如果...就...) ![](https://hackmd.io/_uploads/HybmZEp-T.png) ###### 流程圖的形狀符號都是有意義的,所以不能隨便更改歐~ ---- #### 流程圖的[詳細資訊](https://asana.com/zh-tw/resources/what-is-a-flowchart) ---- # 舉個例子 ```python if 身高<=180: 多喝牛奶 ``` ---- ### 條件 ```python a <= b #a小於等於b a >= b #a大於等於b a == b #a等於b,不要和a = b搞混 a != b #a不等於b a == b and b == c #a等於b而且b等於c a == b or b == c #a等於b或b等於c ``` ---- ## if/else-流程圖(如果...否則...) ![](https://hackmd.io/_uploads/ryuyKEa-a.png) ---- 同樣的 ![](https://hackmd.io/_uploads/B1v8NrTZ6.png) ---- ```python! if 分數<60分: 不及格 else: 及格 ``` ---- ![](https://hackmd.io/_uploads/BkmLw86ba.png) ---- ```python if 超市有雞蛋: 買六顆蘋果 else: 買一顆蘋果 ``` ---- #### 除了使用**else**來做二分法外 #### 還可以用**elif**來做多種判別 ---- #### if/else/elif-流程圖(如果...否則如果...) ---- ![](https://hackmd.io/_uploads/HyY3i4T-a.png) ---- ## 假設福利社販賣的食品分成三類 ### 熱量>600大卡為禁止販賣食品 ### 600大卡>=熱量>240大卡為高中部食品 ### 240大卡>=熱量為國中部食品 ---- ```python if cal>600: 所有學生禁止購買! elif cal>240: 國中生禁止購買! elif cal>=0: 皆可購買! else: 這...吃的飽嗎? ``` ---- ##### 眼尖的各位肯定都有發現在if中程式的前方都有四個空格 --- ### 縮排(indentation) 在 Python 中要去判斷「哪些程式碼屬於某層級之下」不是使用大括號 {} ,而是使用縮排判斷。 ---- java ```java if(a>0){ print("a是正數"); } ``` C++ ```cpp if(a>0){ cout<<"a是正數"; } ``` Python ```python if a>0: print("a是正數") ``` ---- 因此縮排在 Python 中是十分重要的,而根據 Python的[協定PEP8](https://peps.python.org/pep-0008/) 的規定,在Python中我們會使用「四個空格」來縮排。 ###### ps 也可以直接按一下tab --- # 小練習 ---- ### 判斷成績 output ```python 輸入成績:95 你好棒! 輸入成績:60 至少及格 輸入成績:52 記得補考 輸入成績:39 直接死當 ``` ---- ```python grade = float(input("輸入成績")) if grade>=80 : print("你好棒!") elif grade>=60 : print("至少及格") elif grade>=40 : print("記得補考") else: print("直接死當") ``` --- ## 修復問題 #### 甲車比乙車慢怎麼辦 ---- #### 思路1:直接結束 ```python Acar = float(input("輸入甲車時速")) Bcar = float(input("輸入乙車時速")) if Acar <= Bcar : print("甲車追不上乙車") else: x = float(input("輸入甲乙距離")) delta = (Acar-Bcar)/60/60*1000 time = float(x/delta) print("甲追到乙所需時間:"+str(time)+"s") ``` ---- #### 思路2:讓乙追甲 ```python Acar = float(input("輸入甲車時速")) Bcar = float(input("輸入乙車時速")) x = float(input("輸入甲乙距離")) if Acar == Bcar : print("甲車追不上乙車") elif Acar < Bcar: delta = (Bcar-Acar)/60/60*1000 time = float(x/delta) print("乙追到甲所需時間:"+str(time)+"s") else: delta = (Acar-Bcar)/60/60*1000 time = float(x/delta) print("甲追到乙所需時間:"+str(time)+"s") ``` ---- #### 還有其他的嗎?

    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