TypeError: 'int' object is not subscriptable
Solution 1:
The error is exactly what it says it is; you're trying to take sumall[0]
when sumall
is an int and that doesn't make any sense. What do you believe sumall
should be?
Solution 2:
If you want to sum the digit of a number, one way to do it is using sum()
+ a generator expression:
sum(int(i) for i in str(155))
I modified a little your code using sum()
, maybe you want to take a look at it:
birthday = raw_input("When is your birthday(mm/dd/yyyy)? ")
summ = sum(int(i) for i in birthday[0:2])
sumd = sum(int(i) for i in birthday[3:5])
sumy = sum(int(i) for i in birthday[6:10])
sumall = summ + sumd + sumy
print "The sum of your numbers is", sumall
sumln = sum(int(c) for c in str(sumall)))
print "Your lucky number is", sumln