だから、私はそれがユーザーによって入力されたテキストを取って辞書を作成することになっているいくつかのコードです。私はなぜmain()関数を呼び出すときにトレースバックエラーが発生するのか教えてください。main()を呼び出すときにエラーが発生するのはなぜですか?
def build_index(text):
index = {}
words = text.split()
position = 0
for x in text:
if x.isalpha() == False and x.isdigit() == False:
text.join(x)
else:
text.replace(x,'')
while position < len(words):
nextword = words[position]
if nextword in index:
ref = index[nextword]
ref.append(position)
index[nextword] = ref
else:
list = []
list.append(position)
index[nextword] = list
position += 1
def displayindex(index):
keys = sorted(index.keys())
for key in keys:
print(key + ':' + str(index[key]))
def main():
text = input("enter text")
build_index(text)
displayindex(index)
main()
トレースバックエラーを送信できますか? –
Btwでは、 'text.join(x)'と 'text.replace(x、 '')'の戻り値を何にも割り当てていません。彼らは呼び出された文字列を変更しません。あなたが要求した変更で新しい文字列を返します。 –
あなたの質問に_complete_ tracebackを含めるように質問してください。それは同じ問題に遭遇した他の人にあなたの疑問を助けるでしょう。また、他の人がこの質問を見つけるのを助けるために、(NameErrorのように)発生した例外の名前を含むタイトルを編集した場合にも役立ちます。 –