[7 kyu] Square Every Digit

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, because 92 is 81 and 12 is 1.

Note: The function accepts an integer and returns an integer

Solution :

def square_digits(num):
    square = ""
    strtype_num = str(num)
    for number in strtype_num:
        square_num = str(int(number) * int(number))
        square += square_num
    result = int(square)
    return result
发布了16 篇原创文章 · 获赞 0 · 访问量 45

猜你喜欢

转载自blog.csdn.net/HM_773_220/article/details/104771972
今日推荐