Trying to take an integer and return it from the function as an descending integer.
I did it first like this:
def Descending_Order(num):
n = str(num)
return(int(n[::-1]))
Because the tests only had numbers that were in descending order; kinda cheezy but hey it worked.. Now I want to do a number that is any number and make it return the largest to smallest number.
As you can see i tried to dump the int into a string (n) and manipulate it like an array I suppose.
EG:
1201 would return 2110
def Descending_Order(num):
n = str(num)
i = 0
swap = 0
while i < len(n):
if i+1>len(n):
break
elif n[i] < n[i+1]:
swap = n[i]
n[i]= n[i+1]
n[i+1]=swap
i+=1
else:
i+=1
return(n)
print(Descending_Order(1201))