Python 代码抛出错误,之前它工作正常 def main(): 数字=[ “不”, "一",, “两个”, "三",, "四",, "五",, “六”, “七”, "八",, “九” ‘十’ text_one='挂在墙上的绿色瓶子' text\u two=“\n如果一个绿色瓶子\n不小心掉下来\n就会掉下来” #这个循环的每次迭代都会打印出这首歌的一节 对于范围(10,0,-1)内的i: file=open('ten.txt','a') file.write(数字[i]+'') file.write(text_one+'') file.write(数字[i]+'') file.write(text_one+'') file.write(text_two+“”) 文件写入(数字[i-1]+'') file.write(text_one+'') file.close()文件 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': main() 文件“C:\Program Files(x86)\Wing IDE 101 5.1\src\debug\tserver\\u sandbox.py”,第32行,在 文件“C:\Program Files(x86)\Wing IDE 101 5.1\src\debug\tserver\\u sandbox.py”,第22行,在main中 builtins.Indexer错误:列表索引超出范围

Python 代码抛出错误,之前它工作正常 def main(): 数字=[ “不”, "一",, “两个”, "三",, "四",, "五",, “六”, “七”, "八",, “九” ‘十’ text_one='挂在墙上的绿色瓶子' text\u two=“\n如果一个绿色瓶子\n不小心掉下来\n就会掉下来” #这个循环的每次迭代都会打印出这首歌的一节 对于范围(10,0,-1)内的i: file=open('ten.txt','a') file.write(数字[i]+'') file.write(text_one+'') file.write(数字[i]+'') file.write(text_one+'') file.write(text_two+“”) 文件写入(数字[i-1]+'') file.write(text_one+'') file.close()文件 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': main() 文件“C:\Program Files(x86)\Wing IDE 101 5.1\src\debug\tserver\\u sandbox.py”,第32行,在 文件“C:\Program Files(x86)\Wing IDE 101 5.1\src\debug\tserver\\u sandbox.py”,第22行,在main中 builtins.Indexer错误:列表索引超出范围,python,python-3.x,Python,Python 3.x,这在以前是有效的,但现在它抛出了一个错误。有人能看到我把事情搞砸了吗?您的最后一个条目似乎缺少一个逗号: def main(): numbers = [ 'No', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine' 'Ten' ] text_one = 'green bottles\nHanging on the wall' text_two = "\nAnd if one green b

这在以前是有效的,但现在它抛出了一个错误。有人能看到我把事情搞砸了吗?

您的最后一个条目似乎缺少一个逗号:

def main():
    numbers = [
    'No',
'One',
'Two',
'Three',
'Four',
'Five',
'Six',
'Seven',
'Eight',
'Nine'
'Ten' ]
text_one = 'green bottles\nHanging on the wall'
text_two = "\nAnd if one green bottle\nShould accidentally fall\nThere'll be"
# Each iteration of this loop prints one verse of the song

for i in range(10, 0, -1):         
    file=open('ten.txt', 'a')
    file.write(numbers[i]+' ')
    file.write(text_one+' ')
    file.write(numbers[i]+' ')
    file.write(text_one+' ') 
    file.write(text_two+' ')
    file.write(numbers[i-1]+' ')
    file.write(text_one+' ')
    file.close()

if __name__ == '__main__':
    main()
File "C:\Program Files (x86)\Wing IDE 101 5.1\src\debug\tserver\_sandbox.py", line 32, in <module>
  File "C:\Program Files (x86)\Wing IDE 101 5.1\src\debug\tserver\_sandbox.py", line 22, in main
builtins.IndexError: list index out of range
“九”#
'Nine' #<- here
'Ten' ]