Created
April 3, 2020 05:31
-
-
Save Celia-code/98de03f496326fdb43c67e60f4b51f78 to your computer and use it in GitHub Desktop.
for 條件語句
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 打印 1—100間的偶數 | |
# 首先創建一個1—100的集合,利用range函數,生成(1-100)的區間,所以最後得+1。 | |
num = range(1, 101) | |
for n in num: | |
if n % 2 == 0: | |
print(n) | |
else: | |
print("以上數字為1-100之内的偶數") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment