python
20200919
x = 50
y = 60
if x > y: # >為關係運算子
print("x>y")
x = 50
y = 60
if x > y:
print("x>y")
else:
print("x<y")
score = float(input("請輸入成績分數: "))
if score >= 90:
print("優等")
elif score < 90 and score >= 80:
print("甲等")
elif score < 80 and score >= 70:
print("乙等")
elif score < 70 and score >= 60:
print("丙等")
else:
print("不及格")
運算子 | 名稱 |
---|---|
< | 小於 |
<= | 小於等於 |
> | 大於 |
>= | 大於等於 |
== | 等於 |
!= | 不等於 |
for i in range(5):
print(i)
list1 = ["貓", "狗", "花", "鳥"]
for name in list1:
print(name)
for i in range(5):
if i == 3:
break #break(停止迴圈)
print(i)
# 執行結果:到3時停止迴圈
# 0
# 1
# 2
for i in range(5):
if i == 3:
continue #continue(跳過這次,繼續執行下個循環)
print(i)
# 執行結果:少印5
# 0
# 1
# 2
# 4
for i in range(10):
if i == 5:
pass # 尚未要撰寫程式,只是跳過 i==5 狀況下要處理的內容。
print(i) # i==5 時仍然會列印出來。
range(5) # 0,1,2,3,4
range(5, 10) # 5,6,7,8,9
range(5, 10, 2) # 5,7,9 每隔2
continue、break、pass 均可用在while內
i = 0
while i<5:
print(i)
i = i + 1
while True:
num = int(input("number: "))
if num == -1:
break # break 跳出迴圈
print(num)
S20200919 By YTC
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.
Syncing