This is what I want to accomplish:
- let the user type in a number with four digits
- if this number is not equal to 6174 (Kaprekar’s constant) then sort the numbers in two ways: a. from the biggest to the smallest number b. from the smallest to the biggest
- Subtract the bigger number with the smaller
- If the result is not equal to 6174, then do the calculation again and write the result for each and every calculation
- When the result is equal to 6174, write a message to show that the calculation is done
This is what I’ve tried:
print("type in a number")
number = (input())
while number != 6174:
start_big = "".join(sorted(number, reverse=True))
start_small = "".join(sorted(number))
number = (int(start_big)-int(start_small))
print(number)
print("Calculation finnished!")
I’m getting the error:
start_big = "".join(sorted(number, reverse=True)) TypeError: 'int'
object is not iterable