🔥 Burn Fat Fast. Discover How! 💪

def replaceDigit(x, d1, d2): result = 0 multiply = 1 | CODING SOLUTION - Placement Jobs & Materials

def replaceDigit(x, d1, d2):
result = 0
multiply = 1

while (x // 10 > 0):

# Take remainder of number
# starting from the unit
# place digit
remainder = x % 10

# check whether it is
# equal to the digit
# to be replaced.if yes
# then replace
if (remainder == d1):
result = (result + d2 *
multiply)

else: # else remain as such
result = (result + remainder *
multiply)

# Update and move forward
# from unit place to hundred
# place and so on.
multiply *= 10
x = int(x / 10) # update the value

# check whether it is equal to the digit
# to be replaced.if yes then replace
if (x == d1):
result = result + d2 * multiply

else: # else remain as such
result = result + x * multiply
return result


# Driver code
x = 645
d1 = 6
d2 = 5
print(replaceDigit(x, d1, d2))

Python
Replace single digit code
Telegram - t.me/codingsolution_IT