{%hackmd theme-dark %} # Computer Science Club (7) --- ## Function 練習 ---- ## Prime Number [Problem Link](http://203.64.191.163/ShowProblem?problemid=a437) 寫一個判斷是否為 `prime` 的函數。 ---- ## Code ```python= def isprime(n): if n == 2: return True if n % 2 == 0 or n < 2: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True for _ in range(10): n = int(input()) if isprime(n): print('yes') else: print('no') ``` ---- ## Calculation [Problem Link](http://203.64.191.163/ShowProblem?problemid=a435) 寫一個回傳答案的函數。 ---- ## Code ```python= def calc(a, x, b): res = 0 # result 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 else: res = a ** b return res a = int(input()) x = input() b = int(input()) print(calc(a, x, b)) ``` --- ## Import 練習 ---- Coming...
{"metaMigratedAt":"2023-06-15T20:39:24.213Z","metaMigratedFrom":"YAML","title":"Computer Science Club (7)","breaks":true,"contributors":"[{\"id\":\"6587fbcb-5744-488e-ac7d-8d93a89a11f4\",\"add\":1001,\"del\":82}]"}
   changed 4 years ago 298 views