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
  Loop of sums MathFreak 2 52 Mar-20-2019, 10:07 PM
Last Post: MathFreak
  2D arrays and appending values using a loop Pythonhelp82 1 50 Mar-18-2019, 01:04 PM
Last Post: scidam
  slicing words in a while loop missus_brown 4 82 Mar-18-2019, 01:13 AM
Last Post: scidam
  Incremental loop? Headphone256 5 131 Mar-17-2019, 04:46 PM
Last Post: perfringo
  Sentinel Controlled Loop adrury2 3 103 Mar-12-2019, 10:27 PM
Last Post: adrury2
  How to stop a loop? beginner1996 2 139 Mar-08-2019, 08:17 AM
Last Post: perfringo
  Program that, inside a loop, does multiple things. needs to print in a certain way reidmcleod 1 132 Feb-19-2019, 02:35 PM
Last Post: marienbad
  while loop on a calculator missus_brown 3 176 Feb-10-2019, 08:19 PM
Last Post: ichabod801
  Help With While Loop and Append laprus 13 435 Feb-07-2019, 07:04 AM
Last Post: perfringo
  Using Pandas to save csv file into mysql database with for loop kirito85 4 167 Feb-05-2019, 01:13 AM
Last Post: kirito85

Forum Jump:


Users browsing this thread: 1 Guest(s)