I’m trying to make an easy script in Python which takes a number and saves in a variable, sorting the digits in ascending and descending orders and saving both in separate variables. Implementing Kaprekar’s constant.
It’s probably a pretty noobish question. But I’m new to this and I couldn’t find anything on Google that could help me. A site I found tried to explain a way using lists, but it didn’t work out very well.
Sort the digits in ascending and descending orders:
Like this:
And if you need them to be numbers again (not just strings), call
int()on them:2020-01-30