or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
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.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Python Tutorial 🐍
Chapter 1
📍
GMJH
⏱
2023/07/10
~2023/07/13
Today Topic
Before we start …
Slido
Tools ⚙️
Replit
Warm up 🔥
X = X + 1
特別的運算子
if / else
應該會希望程式在
符合某些條件 的時候
才執行相關的指令 👀
當符合 … 條件時
if
==
跟昨天的=
不一樣 🧠:
跟縮排!python 中的縮排
必須要一致!
conditional operator
條件運算子
==
: 等於!=
: 不等於<
: 小於>
: 大於<=
: 小於等於>=
: 大於等於condition & bool
Example
else
當 條件不符合 時執行
也要注意
:
跟縮排!如果還想要判斷更多形況呢?
elif
判斷
score
通過、被當、死當elif 需要注意的地方
猜測
if+elif
跟if+if
的輸出結果if/else 小練習
試著把剛剛的範例改寫成
if/else
if/else 練習 - 判斷奇偶數
如何判斷奇偶數?
if/elif/else 練習-猜數字
ans
變數guess
guess
大於ans
:輸出
guess is larger than ans
guess
小於ans
:輸出
guess is smaller than ans
guess
等於ans
:輸出
U guess the answer !!!
multi-conditions
程式中要如何表達 一次符合多個條件 呢?
Example
a > 10
且a 是奇數
score > 60
或bouns > 5
bouns > 5
nested if/else
巢狀 if/else
Example
a > 10
且a 是奇數
a>10 and odd
a > 10
且a 是偶數
a>10 and even
Example
a > 10
且a 是奇數
a>10 and odd
a > 10
且a 是偶數
a>10 and even
a > 10
這個條件是共同的!Example
要注意縮排 !!!
小練習
試著把「判斷閏年」用 巢狀 if/else 改寫
if else hell
logic operator
邏輯運算子:
and
or
not
邏輯運算子範例
綜合 if/else 練習 - 閏年判斷
如何判斷機
平年
跟閏年
?規則:
閏年判斷
閏年:
print("leap year")
平年:
print("normal year")
details of bool & other data type
來講一些 boolean 與 其他資料型態 的細節
int & bool
int & bool
0
會被視為False
True
None & bool