Frage

So in this case the integer is 2013, and the maximum number would be 3. How would I proceed to doing so? Any help is appreciated. Thanks!

War es hilfreich?

Lösung

max([int(c) for c in str(2013)])

first you convert the number to a string, this allows to look at every digit one by one, than you convert it into a list of single digits and look for the maximum

an easier to read solution is

max = -1

for c in str(2013):
    i = int(c)
    if i > max:
        max = i
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top