In: Computer Science
Python , no strings, len(), or indexing
Write the function setKthDigit(n, k, d) that takes three
# non-negative integers -- n, k, and d -- where d is a single
digit
# (between 0 and 9 inclusive), and returns the number n but
with
# the kth digit replaced with d. Counting starts at 0 and
goes
# right-to-left, so the 0th digit is the rightmost digit.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. Let me know for any help with any other questions. Thank You! =========================================================================== def setKthDigit(n, k, d): n1 = n // (10 ** (k + 1)) n2 = n % (10 ** (k)) n = n1 * (10 ** (k + 1)) + d * (10 ** (k)) + n2 return n print(setKthDigit(123456789, 0, 0)) print(setKthDigit(123456789, 1, 0)) print(setKthDigit(123456789, 2, 0)) print(setKthDigit(123456789, 3, 0)) print(setKthDigit(123456789, 4, 0)) print(setKthDigit(123456789, 6, 0)) print(setKthDigit(123456789, 7, 0))
=================================================================