Nov-09-2018, 02:44 AM
An obvious implementation of a for loop would limit the number of digits you could count. To prevent that, your iterable should be based upon the number passed in. That would ensure that you have enough iterations for effectively cover the number of digits of any number you could provide.
Instead of repeatedly doing floor division, you could use the values in a range as exponents. This way, each iteration increases the divisor by a magnitude of ten and you simultaneously have your "count" for the output:
On a side note, a function should always have a return. The print() call should be replaced by a return and then you call the function like this:
Instead of repeatedly doing floor division, you could use the values in a range as exponents. This way, each iteration increases the divisor by a magnitude of ten and you simultaneously have your "count" for the output:
for x in range(20): divisor = 10 ** x print(f"For {x}, the divisor is {divisor}.")Now, how could you use that idea in your function?
On a side note, a function should always have a return. The print() call should be replaced by a return and then you call the function like this:
print(displayDigits(26))