Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help change from a while loop to a for loop
#11
(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!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  While loop to run a boolean test vicson 7 70 Nov-16-2018, 11:07 AM
Last Post: buran
  nested while loop flow help Ponamis 4 97 Nov-02-2018, 11:22 PM
Last Post: Ponamis
  beginning python help request (for loop) casey 3 94 Oct-26-2018, 07:26 PM
Last Post: casey
  Loop Homework Help Travisbulls34 5 170 Oct-16-2018, 12:32 AM
Last Post: Larz60+
  .remove() method in for-loop nzcan 7 200 Oct-13-2018, 07:05 PM
Last Post: gruntfutuk
  Issues with Inserting Values into an Empty List with a While Loop TommyMer 2 175 Sep-12-2018, 12:43 AM
Last Post: TommyMer
  Infinite loop/ only half working anclark686 5 267 Sep-09-2018, 07:31 AM
Last Post: buran
  Nested loop Tryhard20 3 270 Sep-05-2018, 04:57 AM
Last Post: volcano63
  Help with 'while' loop! Python 3 rafaelssouzza 2 202 Sep-03-2018, 06:19 PM
Last Post: woooee
  Why is this giving me an infinite loop? wlsa 4 472 Jul-25-2018, 10:11 PM
Last Post: cyberpatje

Forum Jump:


Users browsing this thread: 1 Guest(s)