# Python TQC 201~210 ## 201 偶數判斷 ### 說明: 請使用選擇敘述撰寫一程式,讓使用者輸入一個正整數,然後判斷它是否為偶數(even)。 ### 輸入/輸出 範例輸入: :::success 15 ::: :::success 38 ::: 範例輸出: :::success 15 is not an even number ::: :::success 38 is an even number ::: ### Code: ```python number = eval(input()) if number%2 == 0: print('%d is an even number'%number) else: print('%d is not an even number'%number) ``` ## 202 倍數判斷 ### 說明: 請使用選擇敘述撰寫一程式,讓使用者輸入一個正整數,然後判斷它是3或5的倍數,顯示【x is amultiple of 3.】或【x is a multiple of 5.】;若此數值同時為3與5的倍數,顯示【x is a multiple of 3 and 5.】;如此數值皆不屬於3或5的倍數,顯示【x is not amultiple of 3 or 5.】,將使用者輸入的數值代入x。 ### 輸入/輸出 範例輸入: :::success 55 36 92 15 ::: 範例輸出: :::success 55 is a multiple of 5. 36 is a multiple of 3. 92 is not a multiple of 3 or 5. 15 is a multiple of 3 and 5. ::: ### Code: ```python x = eval(input()) if x%3==0 and x%5==0: print('%d is a multiple of 3 and 5.'%x) elif x%3==0: print('%d is a multiple of 3.'%x) elif x%5==0: print('%d is a multiple of 5.'%x) else: print('%d is not a multiple of 3 or 5.'%x) ``` ## 203 閏年判斷 ### 說明: 請使用選擇敘述撰寫一程式,讓使用者輸入一個西元年份,然後判斷它是否為閏年(leap year)或平年。其判斷規則為:每四年一閏,每百年不閏,但每四百年也一閏。 ### 輸入/輸出 範例輸入: :::success 2020 ::: :::success 2045 ::: 範例輸出: :::success 2020 is a leap year ::: :::success 2045 is not a leap year ::: ### Code: ```python year = eval(input()) if year%400 == 0 : print('%d is a leqp year'%year) elif year%100 == 0: print('%d is not a leqp year'%year) elif year%4==0: print('%d is a leqp year'%year) else: print('%d is not a leqp year'%year) ``` ## 204 算術運算 ### 說明: 請使用選擇敘述撰寫一程式,讓使用者輸入兩個整數a、b,然後再輸入一算術運算子 (+、-、*、/、//、%) ,輸出經過運算後的結果。 ### 輸入/輸出 範例輸入: :::success 15 20 \* ::: 範例輸出: :::success 300 ::: ### Code: ```python a = eval(input()) b = eval(input()) operator = input() if operator == '+': print(a+b) elif operator == '-': print(a-b) elif operator == '*': print(a*b) elif operator == '/': print(a/b) elif operator == '//': print(a//b) elif operator == '%': print(a%b) ``` ## 205 字元判斷 ### 說明: 請使用選擇敘述撰寫一程式,讓使用者輸入一個字元,判斷它是包括大、小寫的英文字母(alphabet)、數字(number)、或者其它字元(symbol)。例如:a為英文字母、9為數字、$為其它字元。 ### 輸入/輸出 範例輸入: :::success @ ::: :::success c ::: :::success 5 ::: 範例輸出: :::success @ is a symbol. ::: :::success c is an alphabet. ::: :::success 5 is a number. ::: ### Code: ```python char = input() if ('a' <= char <= 'z') or ('A' < char < 'Z'): print('%c is an alphabet.'%char) elif ('0' <= char <= '9'): print('%c is an number.'%char) else: print('%c is an symble.'%char) ``` ## 206 等級判斷 ### 說明: 請使用選擇敘述撰寫一程式,根據使用者輸入的分數顯示對應的等級。標準如下表所示: | 分數 | 等級 | | :--------: | :--------: | | 80~100 | A | | 70~79 | B | | 60~69 | C | | <=59 | F | ### 輸入/輸出 範例輸入: :::success 69 ::: 範例輸出: :::success C ::: ### Code: ```python score = eval(input()) if 80<= score <= 100: print('A') elif 70<= score <=79: print('B') elif 60<= score <=69: print('C') elif score<= 59: print('F') ``` ## 207 折扣方案 ### 說明: 請使用選擇敘述撰寫一程式,要求使用者輸入購物金額,購物金額需大於8,000(含)以上,並顯示折扣優惠後的實付金額。購物金額折扣方案如下表所示: | 金額 | 折扣 | | :--------: | :--------: | | 8000(含) | 以上9.5折 | | 18000(含) | 以上9折 | | 28000(含) | 以上8折 | | 38000(含) | 以上7折 | ### 輸入/輸出 範例輸入: :::success 25000 ::: 範例輸出: :::success 22500 ::: ### Code: ```python cash = eval(input()) if cash >=38000: print(cash*0.7) elif cash >=28000: print(cash*0.8) elif cash >=18000: print(cash*0.9) elif cash >=8000: print(cash*0.95) else: print(cash) ``` ## 208 十進位換算 ### 說明: 請使用選擇敘述撰寫一程式,讓使用者輸入一個十進位整數num(0 ≤ num ≤ 15),將num轉換成十六進位值。 > 轉換規則 = 十進位0 ~ 9的十六進位值為其本身,十進位10 ~ 15的十六進位值為A~F。 ### 輸入/輸出 範例輸入: :::success 13 ::: :::success 5 ::: 範例輸出: :::success D ::: :::success 5 ::: ### Code: ```python num = eval(input()) print('%X'%num) ``` ## 209 距離判斷 ### 說明: 請使用選擇敘述撰寫一程式,讓使用者輸入一個點 的平面座標x和y值,判斷此點是否與點(5, 6)的距離 小於或等於15,如距離小於或等於15顯示【Inside】 ,反之顯示【Outside】。 > 計算平面上兩點距離的公式:  ### 輸入/輸出 範例輸入: :::success 7 20 ::: :::success 20 35 ::: 範例輸出: :::success Inside ::: :::success Outside ::: ### Code: ```python x = eval(input()) y = eval(input()) dis = pow((pow(x-5,2)+pow(y-6,2)),0.5) if dis <= 15: print('Inside') else: print('Outside') ``` ## 210 三角形判斷 ### 說明: 請使用選擇敘述撰寫一程式,讓使用者輸入三個邊長,檢查這三個邊長是否可以組成一個三角形。若可以,則輸出該三角形之周長;否則顯示【Invalid】。 > 檢查方法 = 任意兩個邊長之總和大於第三邊長。 ### 輸入/輸出 範例輸入: :::success 5 6 13 ::: :::success 2 2 2 ::: 範例輸出: :::success Invalid ::: :::success 6 ::: ### Code: ```python x = eval(input()) y = eval(input()) z = eval(input()) if x+y > z and x+z > y and y+z > x: print(x+y+z) else: print('Invalid') ``` --- 相關文章: [123](ttttt) ###### tags: `python`
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.