--- tags: csc --- {%hackmd theme-dark %} Computer Science Club (2) === Online Judge --- [Dandanjudge](http://dandanjudge.fdhs.tyc.edu.tw/) IDE --- [Google Colab](https://colab.research.google.com/) Registration --- ![](https://i.imgur.com/VwpdMtx.png) p1. a435 --- ### 題目連結 [a435: Calculation](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a435) ### 題解 讀入使用 `input()`, 如果要運算必須轉成 `int` 型態, 再用 `if` 一一列出運算符號的運算方法即可。 基礎 `code`: ```python= a = int(input()) x = input() b = int(input()) res = 0 if x == '+': res = a + b elif x == '-': res = a - b elif x == '*': res = a * b elif x == '/': res = a / b elif x == '//': res = a // b elif x == '%': res = a % b elif x == '**': res = a ** b print(res) ``` 進階 `code`: ```python= print(eval(input() + input() + input())) ``` p2. a437 --- ### 題目連結 [a437: Prime Number](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a437) ### 題解 簡單來說, `Prime Number` 就是質數, 那要怎麼判斷質數呢? 採 `試除法`:for $i=2\sim\sqrt{n}$, 可以使用迴圈 (for, while) 搭配 if 判斷。 `code`: ```python= for _ in range(10): x = int(input()) isprime = True for i in range(2, int(x ** 0.5) + 1): if x % i == 0: isprime = False break if isprime: print('yes') else: print('no') ``` p3. a438 --- ### 題目連結 [a438: Weighted Average](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a438) ### 題解 直接運算, 無條件捨去可以使用 `//` 的整除運算。 基礎 `code`: ```python= a = int(input()) b = int(input()) c = int(input()) d = int(input()) e = int(input()) f = int(input()) g = int(input()) sum = a * 2 + b * 2 + c * 1 + d * 4 + e * 4 + f * 4 + g * 1 print(sum // (2 + 2 + 1 + 4 + 4 + 4 + 1)) ``` 進階 `code`: ```python= a, w = [int(input()) for _ in range(7)], [2, 2, 1, 4, 4, 4, 1] print(sum([a[i] * w[i] for i in range(7)]) // sum(w)) ``` p4. a427 --- ### 題目連結 [a427: 小魔仙講笑話](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a427) p5. a007 --- ### 題目連結 [a007: K-I-S-S-I-N-G](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a007) p6. a042 --- ### 題目連結 [a042: 買鉛筆](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a042) 解完 6 題了怎麼辦 --- 當然, 前 $6$ 題都基礎題。 如果可以 `AC` a314, 就可以自由使用電腦了。 如果 `AC` 不了 a314, 那就繼續學習 `Python` 相關的其它內容。 [[PYTHON] 基礎語法篇](https://happylearningcoding.blogspot.com/2020/07/python.html) [[PYTHON] DICT 篇](https://happylearningcoding.blogspot.com/2020/07/python-dict.html) [[PYTHON] LIST 篇](https://happylearningcoding.blogspot.com/2020/07/python-list.html) [[PYTHON] STRING 篇](https://happylearningcoding.blogspot.com/2020/07/python-string.html) ### 題目連結 [a314: 喔耶 質數](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a314) ### 輸入 ```python= while 1: try: ''' code ''' except EOFError: break ```