int - How to sort the digits of a number and get another number in Python? -
Beginning on Python and trying to code this program:
a = 0 number = int (Input ("Choose four digit numbers:"), while the number! = 6174: #Captrecor continuously sorted (number) sorted (number, reverse = true) big = "" .joined (sorted (number, reverse = true)) small = "" (Sorted) number = (int) - int (small)) a + = 1 print (a + "repeated.") I get the following error :
sorted (number) typeError: 'int' object is not iterable Then how do I get the number and the second number Do you?
First of all, sorted around a nearby Not only does not change, you need to do something like a = sorted (a) . Now for your example, both of you are trying to work with number as int and a str < / code>. You need to convert between str and int when necessary: a = 0 number = input ("four digit number Select: ") number = =" 6174 ": large =" ".joined (sorted (number, reverse = true)) small =" ".join (sorted (number)) number = str (int ( Big) - int (short end, a a int , so you can 'do not int + str in the previous print statement Either print (str (ara) + "iterations") or <+ code>. < / P>
Comments
Post a Comment