JasonLiu
    • 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
      • Invitee
    • 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
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
Invitee
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
--- type: slide --- <style> html, body, .ui-content { background-color: #333; color: #ddd; } .markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 { color: #ddd; } .markdown-body h1, .markdown-body h2 { border-bottom-color: #ffffff69; } .markdown-body h1 .octicon-link, .markdown-body h2 .octicon-link, .markdown-body h3 .octicon-link, .markdown-body h4 .octicon-link, .markdown-body h5 .octicon-link, .markdown-body h6 .octicon-link { color: #fff; } .markdown-body img { background-color: transparent; } .ui-toc-dropdown .nav>.active:focus>a, .ui-toc-dropdown .nav>.active:hover>a, .ui-toc-dropdown .nav>.active>a { color: white; border-left: 2px solid white; } .expand-toggle:hover, .expand-toggle:focus, .back-to-top:hover, .back-to-top:focus, .go-to-bottom:hover, .go-to-bottom:focus { color: white; } .ui-toc-dropdown { background-color: #333; } .ui-toc-label.btn { background-color: #191919; color: white; } .ui-toc-dropdown .nav>li>a:focus, .ui-toc-dropdown .nav>li>a:hover { color: white; border-left: 1px solid white; } .markdown-body blockquote { color: #bcbcbc; } .markdown-body table tr { background-color: #5f5f5f; } .markdown-body table tr:nth-child(2n) { background-color: #4f4f4f; } .markdown-body code, .markdown-body tt { color: #eee; background-color: rgba(230, 230, 230, 0.36); } a, .open-files-container li.selected a { color: #5EB7E0; } </style> <!-- slide start --> # Python Tutorial 🐍 ## Chapter 2 --- ## 📍 `GMJH` #### ⏱ `2023/07/10` ~ `2023/07/13` --- ## Today Topic - loop - while - for --- # Before we start ... ---- ## Slido - **線上匿名提問** - 問都問 🫵 - [present link](https://wall.sli.do/event/v4NmQd5VwgA4rBrStRi4fk?section=19f4a706-900d-45a0-87e1-46b0ac1176c3) - [admin link](https://admin.sli.do/event/v4NmQd5VwgA4rBrStRi4fk/polls) --- # Tools ⚙️ ---- ## Replit - Online IDE - [replit.com](https://replit.com/) ![](https://hackmd.io/_uploads/Syc6WS_F3.png) --- # Warm up 🔥 ---- # input() , print() ---- # Data types ---- # X = X + 1 ---- # 特別的運算子 <!-- ---- ## Kahoot [Warm up 🧠](https://create.kahoot.it/my-library/kahoots/9c573301-540f-4546-9b3e-c9a4d1adc942) --> ---- ## if / else --- ## Loop ---- 如何讓程式解決「重複」的工作呢? ---- 就要用到「迴圈」這個語法 ---- ## 迴圈 Loop - while loop - for loop --- ## while ---- 用英文來看: **當** ... 時 ---- ## while 語法 ```python3 while 條件: 要執行的程式 ``` 當符合 `條件` 時 <br> 就會重複跑過縮排區塊的程式 ```python3! while True: print("ouo") ``` ---- ## 如何強制停止程式 <br> 當我們不小心寫出無窮迴圈時 要用 `ctrl + c` 停止程式! ---- ## while 範例 跑 `n` 幾次 ```python3! n = 10 i = 0 while i<n: print(i) i=i+1 print("i after while" , i ) ``` ---- ## while 練習:2 的倍數 用 `while` 印出 `0` ~ `100` 所有 `2` 的倍數 ---- ## while 練習:猜數字改寫 把昨天的「猜數字」加上 `while` 讓程式跑到**猜中**為止 沒猜對的話: 就提示大於、小於 ---- ## while 練習:3n+1 循環問題 ![](https://hackmd.io/_uploads/r1zedInK3.png) - `n` 如果是 `奇數` : - `n = 3*n + 1` - `n` 如果是 `偶數` : - `n = n / 2` - 當 `n` 是 `1` 時 : - 程式停止 ---- ## while 搭配 input [zerojudge d070](https://zerojudge.tw/ShowProblem?problemid=d070) - 我們已經會判斷閏年了 - 不過這次程式需要一直讀入 `year` <br> 直到 `year` 是 `0` 為止 --- ## for ---- 一種通常將 `i` 當做變數的迴圈 ---- 通常用於明確知道要跑 `n` 次 ---- ## for 語法 ```python for i in range(10): print( i ) ``` 要注意 `for` 的 `range` 的起始值還有結尾!!! ---- ## for 語法 ```python for i in range(n): print( i ) ``` - `i` 預設都由 `0` 開始 - `i` 不會跑到 `n` - 可以看成在判斷 `i < n` ---- ## for 小練習 輸入一個變數 `n` 並讓程式輸出 `1` ~ `n` ```python n = int(input("enter a number")) # ... ``` ---- ## for 語法變化 `range(起始,結尾)` 並不包含 `結尾` !!! ```python3! for i in range(3,7): print(i) ``` ---- ## for 練習-階層 輸入 `n` 並輸出 `n` 階層 階層定義: - 由 `1` 乘到 `n` - `3!` = `6` - `4!` = `24` - `5!` = `120` ---- ## for 練習-判斷質數 要如何判斷質數呢? Hint : - 質數的定義 - 跟取餘數有關 --- ## nested loop ---- 有提過巢狀 if / else 那當然也有巢狀迴圈 ---- 也記得注意縮排!!! ---- ## Example ```python3 for i in range(10): for j in range(10): print( f"({i},{j})" ) ``` ---- ## 巢狀迴圈練習-9x9乘法表 嘗試用巢狀迴圈印出 9x9 乘法表 ---- ## 巢狀迴圈練習-列出因數 輸入 `n` 並印出 `1` ~ `n` 所有數字各自的因數

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