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/11/07 19:35:49

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系统管理方面的问题,可以帮楼主解决啊!

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关于return的一个小问题def sqrt(x):ans=0if x>=0:while ans*ans python 就是输入'done'的时候,能跳出while loop,不然就继续在while里面.def userChoice():global nn = donewhile n = done:n = input(Please enter your choice:)userChoice()错在哪了?如果我改成while n==done,然后输入done, python问题,我的function不能return,讲的是一个开关灯的类class LightSwitch:def __init__(self,condition):self.is_on = conditionif not isinstance(condition,bool):InvaildSwitchExpection = TypeError(it is not a right state.format(condition python 如何判断 abc-def-ghi-1 最后一位是不是数字 python新手关于编写函数的问题sum = 0def sum(i1,i2):result = 0for i in range(i1,i2 + 1):result += ireturn resultsum = sum(1,9)print sum(1,9)显示错误,但第8,9行交换下位置,如下所示:sum = 0def sum(i1,i2):result = 0for i in rang python如何把List里的不同数字相加成一个数字比方说sum_elems([1,2,3,4,5]) => 15 要用for loop做. python AttributeError: 'Stack' object has no attribute 'stack'class Stack(object): def _init_(self): self.stack=[] def push(self,object): self.stack.append(object) def pop(self): return self.stack.pop() def length(sel 关于python输出引号的问题def student_data(name,age,StudentNumber,Enroll):result=str([StudentNumber,name,age,Enroll])return result请问为何会使用一个str的name变量,return的那个name是有单引号的?怎样不让它有单引号 Loop the loop中文翻译 python中出现IndentationError:unindent does not match any outer indentation level是什么问题? Python里round 四舍五入问题,round(3.15,1)为什么是3.1而不是3.2 python 如何把list中元素一个对一个的换成对应的数字 list = ['abc', 'def', 'ghi']换成 list = ['101', '102', '103'] 以此类推 在python,def ha(b,c) b是一个string,c是一个隔开.例子:ha('a,b,c',',')->['a','b' ,'c'] 这个咋弄啊 loop是什么意思 Loop梗是什麼?.. VB用法:while..loop loop..while loop..until until..loop loop holes