Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在单独的行上显示“word”结果,并打印包含该单词的句子的第一个单词(Python)_Python - Fatal编程技术网

在单独的行上显示“word”结果,并打印包含该单词的句子的第一个单词(Python)

在单独的行上显示“word”结果,并打印包含该单词的句子的第一个单词(Python),python,Python,我在这个问题上遇到了麻烦,有人能帮我吗 编写一个程序读取book.txt,询问用户密码是什么,然后只打印包含该单词的所有句子的第一个单词,忽略大小写。包括包含子字符串的所有句子,即使它构成单词的一部分 book.txt文件每行有一句话,如下所示: The room was dark and dreary. Beware what lies beneath. She could barely make out the back wall. Treasure was piled in the nea

我在这个问题上遇到了麻烦,有人能帮我吗

编写一个程序读取book.txt,询问用户密码是什么,然后只打印包含该单词的所有句子的第一个单词,忽略大小写。包括包含子字符串的所有句子,即使它构成单词的一部分

book.txt文件每行有一句话,如下所示:

The room was dark and dreary.
Beware what lies beneath.
She could barely make out the back wall.
Treasure was piled in the nearest corner, in the dark shadows.
Is this safe, she thought to herself, accidentally stubbing her toe on the dark carpet.
Mister Lieth said it would be cold.
Suddenly, a gust of wind rushed through the door from behind her.
In the wind, the candle struggled, plunging the room into semidarkness.
The thought of the already darkened room having still less light did not appeal to her.
Shivering, she closed the door, wishing she had brought a scarf.
Well and good, she had to focus before it was dark outside.
Black and grey shadows were all she had to believe in.
Password: dark
the
treasure
is
in
the
well
您的程序应如下所示:

The room was dark and dreary.
Beware what lies beneath.
She could barely make out the back wall.
Treasure was piled in the nearest corner, in the dark shadows.
Is this safe, she thought to herself, accidentally stubbing her toe on the dark carpet.
Mister Lieth said it would be cold.
Suddenly, a gust of wind rushed through the door from behind her.
In the wind, the candle struggled, plunging the room into semidarkness.
The thought of the already darkened room having still less light did not appeal to her.
Shivering, she closed the door, wishing she had brought a scarf.
Well and good, she had to focus before it was dark outside.
Black and grey shadows were all she had to believe in.
Password: dark
the
treasure
is
in
the
well
您可以在中使用


每个句子都在一行吗?欢迎来到StackOverflow。为了获得最好的帮助,建议您共享最小的代码,以便更好地再现问题。是的,它位于单独的行上,通过描述完成此任务所需的每个步骤开始。描述应使用英语。忘了Python和计算机编程语言吧。这是一个家庭作业问题,你甚至还没有试图解决它。你必须展示你已经尝试了什么,以及你到底遇到了什么,也就是说,不仅仅是一般的问题。非常感谢。