First, putting sorted
around an iterable doesn't change the iterable itself. You need to do something like a = sorted(a)
.
Now as for your example, you are trying to work with number
as both an int
and a str
. You need to convert between str
and int
when necessary here:
a=0
number = input("Choose a four digit number: ")
while number != "6174":
large = "".join(sorted(number, reverse=True))
small = "".join(sorted(number))
number = str(int(large) - int(small))
a+=1
print(a, "iterations.")
Finally, a
is an int
, so you can't do int+str
in the last print statement. Either put a comma like I have or do print(str(a)+" iterations")
.