帮我写一个寻找列表中含有Material,Exclouce,Laber cos且一旦找到Material就给包含他们的那一行加60分,找到Exclouce或Laber cos那一行就加20分,一个没有就0分,三个同时有就加100分,且要求每行的内容要用户输入,输入内容为句子,要求检索的词语藏在句子中,最后输出整体列表的程序
时间: 2024-03-10 07:49:45 浏览: 11
好的,以下是你需要的程序,使用 Python 实现:
```python
def find_and_score(lines):
score = 0
for line in lines:
if "Material" in line:
if "Exclouce" in line and "Laber cos" in line:
score += 60
else:
score += 20
elif "Exclouce" in line or "Laber cos" in line:
score += 20
if score == 100:
score += 100
return score
def score_lines(lines):
for i, line in enumerate(lines):
score = find_and_score(line)
print(f"Line {i+1}: {line}, Score: {score}")
def main():
lines = []
for i in range(5):
line = input(f"Please input the sentence of line {i+1}: ")
lines.append(line.split())
score_lines(lines)
if __name__ == "__main__":
main()
```
在这个程序中,我们使用了 `input()` 函数来获取用户输入的每一行的句子,使用 `split()` 函数将句子分割成单词,并将每行的单词列表添加到 `lines` 列表中。之后程序会依次遍历每一行判断是否包含所有三个关键词,如果是则加60分;如果只有其中一个关键词,则加20分;如果三个关键词同时存在,则加100分。遍历完成后输出每一行的得分,最后输出整体列表得分。
注意:这里同样使用了一个嵌套列表 `lines`,其中每个内部列表代表一行。如果你的列表形式不同,可以根据实际情况进行修改。