Python Loop问题def read_poetry_form_description(poetry_forms_file):""" (file open for reading) -> poetry patternPrecondition:we have just read a poetry form name from poetry_forms_file.Return the next poetry pattern from poetry_forms_file."""output
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 16:52:24
Python Loop问题def read_poetry_form_description(poetry_forms_file):""" (file open for reading) -> poetry patternPrecondition:we have just read a poetry form name from poetry_forms_file.Return the next poetry pattern from poetry_forms_file."""output
Python Loop问题
def read_poetry_form_description(poetry_forms_file):
""" (file open for reading) -> poetry pattern
Precondition:we have just read a poetry form name from poetry_forms_file.
Return the next poetry pattern from poetry_forms_file.
"""
output_syllables = []
output_rhyme = []
a = poetry_forms_file.readlines()
i = 0
b = []
while a[i] = '\n':
b = a[i].strip('\n').split()
output_syllables.append(a[i][0])
output_rhyme.append(a[i][2])
i += 1
return [output_syllables,output_rhyme]
def read_poetry_form_descriptions(poetry_forms_file):
""" (file open for reading) -> dict of {str:poetry pattern}
Return a dictionary of poetry form name to poetry pattern for the
poetry forms in poetry_forms_file.
"""
output = {}
b = []
for b in poetry_forms_file:
b = b.strip('\n')
if b.isalpha():
output[b] = read_poetry_form_description(poetry_forms_file)
return output
下面这个是要read的文件 每一种都是一种诗的格式形容
Haiku
5 *
7 *
5 *
Sonnet
10 A
10 B
10 A
10 B
10 C
10 D
10 C
10 D
10 E
10 F
10 E
10 F
10 G
10 G
Limerick
8 A
8 A
5 B
5 B
8 A
Quintain (English)
0 A
0 B
0 A
0 B
0 B
Rondeau
8 A
8 A
8 B
8 B
8 A
8 A
8 A
8 B
4 C
8 A
8 A
8 B
8 B
8 A
4 C
然后运行这个方程之后只有第一种诗return出来了 求教为什么不继续loop 实在是不懂计算机.
Python Loop问题def read_poetry_form_description(poetry_forms_file):""" (file open for reading) -> poetry patternPrecondition:we have just read a poetry form name from poetry_forms_file.Return the next poetry pattern from poetry_forms_file."""output
楼主的程序方面逻辑有问题啊,不能这样的.
如果需要的话,可以帮楼主一起分析这个难问题.
以后要是有python的开发需求,比如运维监控管理的开发,shell开发,或者是linux系统管理方面的问题,可以帮楼主解决啊!