对一个数的每一位数字求平方

题目描述:

# Welcome. In this kata, you are asked to square every digit of a number.
# For example, if we run 9119 through the function, 811181 will come out,
# Note: The function accepts an integer and returns an integer

我的解答:
def square_digits(num):
a = ''
for i in str(num):
a = a + str(int(i)**2)
return int(a)

posted on 2020-04-05 20:16  阿虾  阅读(279)  评论(0编辑  收藏  举报

导航