Write a Python program to create the next bigger number by rearranging the digits.
INPUT:
def rearrange_bigger(n):
#Break the number into digits and store in a list
nums = list(str(n))
for i in range(len(nums)-2,-1,-1):
if nums[i] < nums[i+1]:
z = nums[i:]
y = min(filter(lambda x: x > z[0], z))
z.remove(y)
z.sort()
nums[i:] = [y] + z
return int("".join(nums))
return False
n = 12
print("Original number:",n)
print("Next bigger number:",rearrange_bigger(n))
n = 10
print("\nOriginal number:",n)
print("Next bigger number:",rearrange_bigger(n))
n = 201
print("\nOriginal number:",n)
print("Next bigger number:",rearrange_bigger(n))
n = 102
print("\nOriginal number:",n)
print("Next bigger number:",rearrange_bigger(n))
n = 445
print("\nOriginal number:",n)
print("Next bigger number:",rearrange_bigger(n))
OUTPUT:
THANK YOU..!!💫
0 Comments