gpt4 book ai didi

python - 类型错误 : 'int' object is not subscriptable

转载 作者:IT老高 更新时间:2023-10-28 22:22:29 29 4
gpt4 key购买 nike

我正在尝试创建一个简单的程序,根据命理告诉你你的幸运数字。我不断收到此错误:

File "number.py", line 12, in <module>
sumln = (int(sumall[0])+int(sumall[1]))
TypeError: 'int' object is not subscriptable

我的脚本是:

birthday = raw_input("When is your birthday(mm/dd/yyyy)? ")
summ = (int(birthday[0])+int(birthday[1]))
sumd = (int(birthday[3])+int(birthday[4]))
sumy= (int(birthday[6])+int(birthday[7])+int(birthday[8])+int(birthday[9]))
sumall = summ + sumd + sumy
print "The sum of your numbers is", sumall
sumln = (int(sumall[0])+int(sumall[1]))
print "Your lucky number is", sumln`

最佳答案

错误正是它所说的;当 sumall 是一个 int 并且没有任何意义时,您正在尝试使用 sumall[0]。你认为 sumall 应该是什么?

关于python - 类型错误 : 'int' object is not subscriptable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9054854/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com