I'm doing python tutorials on pyschools.com, and to answer the above question, my method is converting each integer to a string, reversing the order of the characters, then converting it back to an integer, dividing it by 10, and adding the remainders. This is probably a very muddled way to accomplish this, but it's the only way I can think of.
My code is as follows:`
def getSumOfFirstDigit(num):
answer=0
for number in num:
str(number)
number[::-1]
int(number)
t = number%10
answer=answer+t
return answer`
When I run it with the example: getSumOfFirstDigit([12, 23, 34, 45, 56])
, it returns the error:
Traceback (most recent call last):
File "Code", line 5, in getSumOfFirstDigit
TypeError: 'int' object has no attribute '__getitem__'`
I thought the "str(number)" would take care of what the error says.