Python Forum
Help change from a while loop to a for loop - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Help change from a while loop to a for loop (/thread-13962.html)

Pages: 1 2


RE: Help change from a while loop to a for loop - captwiggum - Nov-09-2018

(Nov-09-2018, 11:20 AM)stullis Wrote: Larz's explanation is the best. As for my suggestion, here's what I had in mind:

def displayDigits(number):
    for x in range(number):
        divisor = 10 ** x

        if number // divisor == 0:
            return x

    return -1 # In case the number is magically too large

print(displayDigits(26))

Thank you!