将出东方 2022-11-07 12:07 采纳率: 80%
浏览 76
已结题

AttributeError: 'int' object has no attribute 'append'

问题遇到的现象和发生背景

运行报错:
AttributeError: 'int' object has no attribute 'append'

用代码块功能插入代码,请勿粘贴截图

序号=[]
数字=[]
for 数 in range(1,10):
数字.append(数)
for 数字 in 数字:
if 数字==1:
序号.append('1st')
elif 数字==2:
序号.append('2nd')
elif 数字==3:
序号.append('3rd')
else:
序号.append(str(数字)+'th')

print(序号)

运行结果及报错内容

AttributeError: 'int' object has no attribute 'append'

我的解答思路和尝试过的方法

尝试用list(),没有解决

我想要达到的结果

序号='1st,2nd,3rd,4th,5th……'

  • 写回答

2条回答 默认 最新

  • 於黾 2022-11-07 13:34
    关注

    for 数字 in 数字:
    自己看看自己写的玩意

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月15日
  • 已采纳回答 11月7日
  • 创建了问题 11月7日