想知道为什么我的代码没有写入新的文本文件。没有错误可以给我一个线索。在
def writeFile (filename, text):
file = open(greenBottle.txt, 'w')
file.write(text)
file.close()
def main (text):
big_nums = ['no','One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten']
text_one = (' green bottles \nHanging on the wall\n')
small_nums = [' no',' one',' two',' three',' four',' five',' six',' seven',' eight',' nine',' ten']
text_two = ('And if one green bottle \nShould accidentally fall\nThere\'ll be')
text_three = (' green bottles \nHanging on the wall\n \n')
result=[]
text=new_string
new_string=''
for i in range(10, 0, -1):
result.append(big_nums[i] + str( text_one))
result.append(big_nums[i] + str( text_one))
result.append(text_two + small_nums[i-1] + text_three)
return result('')
print(''.join(main(text)))
if __name__ == '__main__':
writeFile('greenBottle.txt',text)
main(text)
就我而言,这些行是有缺陷的,应该删除,而且不能从for循环中
return
,只能从函数中删除:重复这句话:
^{pr2}$在我重写你的代码之后:
输出:
相关问题 更多 >
编程相关推荐