梁安哲
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Python if 資訊之芽 梁安哲 2022/03/13 --- ## 課程大綱 Outline ---- 1. 課程回顧 2. 比較運算子 3. 邏輯運算子 4. 基本語法 5. 縮排 6. 花俏語法 --- ## 課程回顧 Recap ---- ### 輸出 ```python= print("萊納,你坐啊") ``` ---- ### 變數 ```python= someInteger = 10 someString = "A for apple, B for ball." someBool = False someFloat = 8.7 ``` ---- ### 輸入 ```python= colossalTitan = input("城牆裡有幾隻超大型巨人?") print("早上好馬萊,現在我有" + colossalTitan + "隻超大型巨人") ``` ---- ### Questions? --- ## 比較運算子 Comparison Operators ---- ### 之前的運算子 ``` python= print(1 + 3 * 3) # ? print("1" + "3" * 3) # ? print(10 / 3) # ? print(10 // 3) # ? print(2 ** 5) # ? ``` ---- ```python= print(1 + 3 * 3) # 10 print("1" + "3" * 3) # 1333 print(10 / 3) # 3.3333... print(10 // 3) # 3 print(2 ** 5) # 32 ``` ---- ### 如果我們想要做這樣的事情 艾蓮·葉卡: 梟他,將這個稱作"尤彌爾的詛咒" 十三年是始祖尤彌爾從力量覺醒到死去之間的時長 沒人擁有超越始祖尤彌爾的力量 只要接近這個時辰軀體就會衰弱...作為容器的使命就算完成了。 ---- ### 翻譯成白話 ---- * 始祖尤彌爾的力量大於所有人的力量 * 繼承巨人之力的人不會活超過13年 ---- ### 要怎麼讓電腦聽懂呢 ```python= powerYmir = 9999 powerEren = 100 statement1 = powerYmir > powerYmir # True yearYmir = 13 yearEren = 13 statement2 = yearEren <= yearYmir # True ``` ---- ### 比較運算子 continued | Operator | Name | Example | | -------- |:------------------------ | ------- | | == | Equal | x == y | | != | Not equal | x != y | | > | Greater than | x > y | | < | Less than | x < y | | >= | Greater than or equal to | x >= y | | <= | Less than or equal to | x <= y ---- ### 非常重要的重點 ```python= a, b, c, d = 1, 2, 3, 4 firstBool, SecondBool = a = b, c == d print(firstBool) # ? print(SecondBool) # ? ``` ---- ### = != == (重要) ```python= a, b, c, d = 1, 2, 3, 4 firstBool = a = b SecondBool = c == d print(firstBool) # 2 print(SecondBool) # False ``` ---- ### Questions? --- ## 邏輯運算子 Logical Operators ---- ### 如果我們還想要做這樣的事情 阿爾敏·亞魯雷特: 再次分成兩組搜索牆面,尤其是大門上方部位 無倫艾蓮何時出現賭塞牆壁都能做出對應的位置 任何時候都能看清並把握狀況的位置... 並且在時機到來前都能安全藏身的位置 ---- ### 一樣翻譯成白話 ---- 同時滿足三個條件的地方 * 隨時對應 * 把握狀況 * 安全藏身 ---- ### 要怎麼讓電腦聽懂呢 ```python= respondAnytime = True niceView = True safe = True optimalLocation = respondAnytime and niceView \ and safe # True ``` ---- ### 邏輯運算子 continued | Operator | Name | Example | | -------- |:------------------------------------------------------- |:--------------------- | | and | Returns True if both statements are true | x < 5 and x < 10 | | or | Returns True if one of the statements is true | x < 5 or x < 4 | | not | Reverse the result, returns False if the result is true | not(x < 5 and x < 10) | ---- ### 善用括號 ```python= print(not True and False or True or False) # ? print(not((True and False) or (True or False))) # False ``` ---- ### Questions? --- ## If ---- ### 進擊的巨人again 米卡莎·阿卡曼: 如果你加入憲兵團,那麼我也會去 而要是你加入駐紮兵團,我也會照做 艾蓮,如果你不在我的身邊,一定會早死的。 ---- ### 再次翻譯成白話 ---- 艾蓮加入調查兵團->米卡莎加入調查兵團 艾蓮加入憲兵團->米卡莎加入憲兵團 艾蓮加入紮駐兵團->米卡莎加入紮駐兵團 (注意一個人一次只能加入一個兵團) ---- ### 一樣我們想要讓電腦聽懂 ```python= erenJoinSurveyCorps = True erenJoinGarrison = False erenJoinMilitaryPoliceBrigade = False if erenJoinSurveyCorps: print("米卡莎加入調查兵團") if erenJoinMilitaryPoliceBrigade: print("米卡莎加入憲兵團") if erenJoinGarrison: print("米卡莎加入紮駐兵團") ``` ---- ### 那些空白是啥酷東西? ---- ### 不合理的敘述 ```python= erenJoinSurveyCorps = True erenJoinGarrison = True erenJoinMilitaryPoliceBrigade = True if erenJoinSurveyCorps: print("米卡莎加入調查兵團") if erenJoinMilitaryPoliceBrigade: print("米卡莎加入憲兵團") if erenJoinGarrison: print("米卡莎加入紮駐兵團") ``` ---- ### 改成合理的敘述 ```python= erenJoinSurveyCorps = True erenJoinGarrison = True erenJoinMilitaryPoliceBrigade = True if erenJoinSurveyCorps: print("米卡莎加入調查兵團") elif erenJoinMilitaryPoliceBrigade: print("米卡莎加入憲兵團") else: print("米卡莎加入紮駐兵團") ``` ---- ### if elif else 三兄弟 ```python= income = int(input()) tax = 0 if income < 0: tax = 0 elif income < 100: tax = income * 0.1 elif income < 200: tax = income * 0.2 elif income < 300: tax = income * 0.3 else: tax = income * 0.4 print(tax) ``` ---- ### Questions? --- ## 縮排 Code Indentation (重要) ---- ```python= computer = 10 user = int(input()) if user > 0: if user > computer: print("you win") else: print("you lose") ``` ---- ```python= computer = 10 user = int(input()) if user > 0: if user > computer: print("you win") else: print("you lose") ``` ---- ### 有哪裡不同? ---- ### 為什麼? ---- ### 縮排是啥? 1. 縮排=程式碼開頭的空白。 2. Python使用縮排表示一個區塊的程式。 ---- ### 錯誤範例 ``` python= a, b = 3, 5 if a > b: print("a is greater than b") print("python ended") ``` ---- ### 正確範例 ```python= a, b = 3, 5 if a > b: print("a is greater than b") print("python ended") ``` ---- ### 縮排是啥? continued 3. 空白的個數為自訂,原則上為四個空白。 4. 同一個區塊內的空白數量需一致。 5. 區塊內不可空白(可用pass規避) ---- ### 錯誤範例 again ```python= if 5 > 2: print("Five is greater than two!") print("Five is greater than two!") ``` ```python= if 5 > 2: #Five is greater than two! ``` ---- ### 正確範例 again ```python= if 5 > 2: print("Five is greater than two!") print("Five is greater than two!") ``` ```python= if 5 > 2: #Five is greater than two! pass ``` ---- ### 現在是...練習時間 [neoj 3010](https://neoj.sprout.tw/problem/3010/) ---- ### Nested if ```python= a, b, c = 1, 2, 3 if c > b: if c > a: print("c is the biggest number") ``` ---- ### 代表我們可以這樣? ![](https://i.imgur.com/crqsI74.jpg) ---- ### 請不要 ---- ### 要善用邏輯運算子 ```python= a, b, c = 1, 2, 3 if c > b and c > a: print("c is the biggest number") ``` ---- ### 使用條件句的邏輯整理 (重要) 1. 開頭一定會有if,其他都是非必要的。 2. 上一個條件不符合時,繼續判斷下一個條件,使用elif 3. 所有條件都不符合時做某些事,使用else 4. if及else只會出現一次,但是可以有複數個elif 5. if一定會出現在第一個,else一定會出現在最後一個(但是不一定有else) ---- ### Questions? ---- ### 現在是...練習時間 [neoj 3011](https://neoj.sprout.tw/problem/3011/) --- ## 花俏語法 Advanced ---- ### 冗長的程式碼 ```python= condition = False a = 0 if condition: a = 1 else: a = -1 ``` ---- ### 三元運算子 Ternary Operator ```python= condition = False a = 1 if condition else -1 ``` --- ### 現在是...作業時間 [neoj 3401](https://neoj.sprout.tw/problem/3401/) [neoj 3402](https://neoj.sprout.tw/problem/3402/) --- ## Thanks

    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