Looking at the original code, this is a poor conversion request. In reality all the loop is doing is count number of digits, so to know how to iterate the loop properly, you need to first know the number of digits. Doesn't make sense.
you can get that simply:
you can get that simply:
num_len = len(str(number))so, to do as loop:
def display_digits(number): counter = 0 for i in str(number): counter += 1 print(counter) display_digits(26) display_digits(261234) # Easy way print('Easy: for 26: {}'.format(len(str(26)))) print('Easy: for 261234: {}'.format(len(str(261234))))results:
Output:2
6
Easy: for 26: 2
Easy: for 261234: 6