在 Unix 中 bash 是什麼?
請說明Python變數的設定規則
請說明Python中escape character的用法和列出常見的例子
設計程式時出現以下錯誤,請協助修正:
AttributeError Traceback (most recent call last)
<ipython-input-8-b9d8f89049c4> in <cell line: 1>()
----> 1 a.upper()
AttributeError: 'int' object has no attribute 'upper'
請Debug以下程式:
a = 235 # integer
b = "two three five" # string
c = True # boolean
d = (2, 3, 5) # tuple
e = [2, 3, 5] # list
f = {"two": 2, "three": 3, "five": 5} # dictionary
type(f)
a.upper()
請解釋以下的程式碼:
from math import log2
count_new = 0
count_york = 0
count_new_york = 0
for i,tok in enumerate(tokens):
if tok == "new":
count_new += 1
try:
next_tok = tokens[i+1]
if next_tok == "york":
count_new_york += 1
except IndexError:
pass
if tok == "york":
count_york += 1
p_new = count_new / len(tokens)
p_work = count_york / len(tokens)
p_new_york = count_new_york / len(tokens)
pmi = log2(p_new_york / (p_new * p_work))
print("p_new =", p_new)
print("p_york =", p_work)
print("p_new_york =", p_new_york)
print("pmi =", pmi)
請為以下的程式碼加上註解:
from math import log2
count_new = 0
count_york = 0
count_new_york = 0
for i,tok in enumerate(tokens):
if tok == "new":
count_new += 1
try:
next_tok = tokens[i+1]
if next_tok == "york":
count_new_york += 1
except IndexError:
pass
if tok == "york":
count_york += 1
p_new = count_new / len(tokens)
p_work = count_york / len(tokens)
p_new_york = count_new_york / len(tokens)
pmi = log2(p_new_york / (p_new * p_work))
print("p_new =", p_new)
print("p_york =", p_work)
print("p_new_york =", p_new_york)
print("pmi =", pmi)
請用Python畫出log2的圖形,並包含程式坐標軸與x=1
Remove the punctuations of a string using Python.
請改進以下程式碼:
from math import log2
count_new = 0
count_york = 0
count_new_york = 0
for i,tok in enumerate(tokens):
if tok == "new":
count_new += 1
try:
next_tok = tokens[i+1]
if next_tok == "york":
count_new_york += 1
except IndexError:
pass
if tok == "york":
count_york += 1
p_new = count_new / len(tokens)
p_work = count_york / len(tokens)
p_new_york = count_new_york / len(tokens)
pmi = log2(p_new_york / (p_new * p_work))
print("p_new =", p_new)
print("p_york =", p_work)
print("p_new_york =", p_new_york)
print("pmi =", pmi)
Please use traditional chinese in all the following response