I'm new to Python, may I ask why does my code not work?
Question: square every digit of a number and concatenate them
Input:9119
Output:811181
my code:
def square_digits(num):
num=str(num)
newnum=""
for i in num:
newnum.append(i**2)
return int(newnum)
why does it state that:
AttributeError: 'str' object has no attribute 'append'
return int(''.join((str(int(c)**2) for c in str(num))))