Python 代码不适用于mt任务3 A453计算,索引器错误:列表索引超出范围 导入json 句子=输入(“请输入句子:”) split句子=句子。split() 分数=[0] 打印(句子) 对于计数,我在枚举中(拆分句子): 如果拆分句子。计数(i)

Python 代码不适用于mt任务3 A453计算,索引器错误:列表索引超出范围 导入json 句子=输入(“请输入句子:”) split句子=句子。split() 分数=[0] 打印(句子) 对于计数,我在枚举中(拆分句子): 如果拆分句子。计数(i),python,Python,您好,我目前正在进行GCSE计算,这是我的a453任务3代码。我试图拆分一个句子,然后保存它,并显示每个单词的位置。最后,我需要一个选项从文件中重建句子。当我运行代码时,一切正常,直到我到达重构部分,它要么以非常混乱的顺序重新创建句子,要么显示以下语法错误: import json sentence = input("Please input a sentence: ") splitsentence = sentence.split() score = [0] print(sentence)

您好,我目前正在进行GCSE计算,这是我的a453任务3代码。我试图拆分一个句子,然后保存它,并显示每个单词的位置。最后,我需要一个选项从文件中重建句子。当我运行代码时,一切正常,直到我到达重构部分,它要么以非常混乱的顺序重新创建句子,要么显示以下语法错误:

import json
sentence = input("Please input a sentence: ")
splitsentence = sentence.split() 
score = [0]
print(sentence)
for count, i in enumerate(splitsentence): 
    if splitsentence.count(i) < 2:
        score.append(max(score)+1)
    else:
        score.append(splitsentence.index(i) +1)
score.remove(0)
print(splitsentence)
print(score)

numberandwordarrays = [score,splitsentence]


numberandword = open("numberandword.txt" , "w")
json.dump(numberandwordarrays, numberandword)
numberandword.close()
menu = input("Decompress? Y/N: ")
if menu.lower() == "y":
    joinwords = open("numberandword.txt", "r")
    recreate = json.load(joinwords)
    jointwords = recreate[1]
    positions = recreate[0]
    print(" ".join(map(jointwords.__getitem__, map(int, positions))))
else:
    print ("Thanks for using my program, have a good day!")
回溯(最近一次呼叫最后一次):
文件“D:\Computing\a453\Task 3.py”,第28行,在
打印(“.join(映射(jointwords.\uuuu getitem\uuuuu,映射(int,positions)))
索引器:列表索引超出范围

有人知道我做错了什么,以及我如何修复它吗?

从位置列表(或iterable)中提取的索引中至少有一个超出jointwords列表的范围


在此行添加断点并调试

请将您的代码粘贴为问题中的文本。谢谢您的帮助,但我是python初学者,因此我不太确定如何添加断点。您能否解释一下我将如何在代码中添加断点。
 Traceback (most recent call last):
  File "D:\Computing\a453\Task 3.py", line 28, in <module>
    print(" ".join(map(jointwords.__getitem__, map(int, positions))))
 IndexError: list index out of range