Tuesday, February 8, 2022

Square Every Digit Python

 

Welcome. In this kata, you are asked to square every digit of a number and concatenate them.

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



def square_digits(num):
    r = ''
    for l in str(num):
     r = r + str((int(l))**2)
    return int(r)
print(square_digits(9119))
def square_digits(num):
    return int(''.join(str(int(d)**2) for d in str(num)))

Training on Square Every Digit | Codewars



Related Posts


No comments :

Post a Comment