我有一个单词列表,我的输入是列表前半部分中的一个单词(在本例中,这个列表是一首德语歌曲)。现在我取这个单词的长度,跳到列表中这个单词的长度,例如,列表中的第一个单词是“Es”,长度是2。现在我们从“Es”数两次,然后用单词“zwei”着陆。我应该检查一下这个单子,看看这个词是否又出现在下半部分。在
程序正常,但问题在于输入。它只需要一个词,看看这个理论是否有效。 这是歌曲列表:“欣”是上半场的最后一个词
song = [
"Es", "gingen", "zwei", "Parallelen",
"ins", "Endlose", "hinaus",
"zwei", "kerzengerade", "Seelen",
"und", "aus", "solidem", "Haus",
"Sie", "wollten", "sich", "nicht", "schneiden",
"bis", "an", "ihr", "seliges", "Grab",
"Das", "war", "nun", "einmal", "der", "beiden",
"geheimer", "Stolz", "und", "Stab",
"Doch", "als", "sie", "zehn", "Lichtjahre",
"gewandert", "neben", "sich", "hin", #End of the first half of the song
"da", "wards", "dem", "einsamen", "Paare",
"nicht", "irdisch", "mehr", "zu", "Sinn",
"Warn", "sie", "noch", "Parallelen",
"Sie", "wusstens", "selber", "nicht",
"sie", "flossen", "nur", "wie", "zwei", "Seelen",
"zusammen", "durch", "ewiges", "Licht",
"Das", "ewige", "Licht", "durchdrang", "sie",
"da", "wurden", "sie" "eins", "in", "ihm",
"die", "Ewigkeit", "verschlang", "sie",
"als", "wie", "zwei", "Seraphim"]
我希望我的输入是列表前半部分的所有单词(本例中是歌曲),而不是一个单词。所以它只输出每行中每个单词的结果(在本例中是一个列表)。在
我希望它能立即打印出前半部分每个单词的每个结果,如果理论成立的话。这将比输出结果更重要:
理论有效/无效
结果1
理论有效/无效
结果2
理论有效/无效
结果3
等等。。。在
代码如下:
^{pr2}$
下面是这个函数的一个版本,它处理列表第一部分中的每个单词。问题说明程序正常工作,所以主逻辑没有改变。在
以下是所做的更改:
input
语句for
循环originalWordSaved
和originalIndex
变量while
循环,因为它只需要每个单词运行一次IndexError
移出try/except块IndexError
,因为这是代码可能引发的唯一错误:应该避免空的except
语句相关问题 更多 >
编程相关推荐