loop在python中什么意思_Python Loop问题

defread_poetry_form_description(poetry_forms_file):"""(fileopenforreading)->poetrypatternPrecondition:wehavejustreadapoetryformnamefrompoetry_forms_file.Returnthenextpoet...

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 实在是不懂计算机。。

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值