Using a while loop checking if condition is met and it will stop if the condition is not met:
x = 4
y = 2
numOfDiv = 0
while x > 0:
x = x // y
numOfDiv += 1
print("number of divison:{}".format(numOfDiv))
Creating a generator function that gives us a value and it will stop generating if the condition isn't met, using the same while loop. We can then iterate from the generator until all the values is exhausted using a for loop.
x = 4
y = 2
def int_div(x,y):
while x > 0:
x,y = x // y, y
yield x
for numOfDiv, value in enumerate(int_div(x,y),1):
pass
print("number of divison:{}".format(numOfDiv))
Using the same generator in a list comprehension to find all the values we want, and then printing the size of the list since that's how many division it made.
x = 4
y = 2
def int_div(x,y):
while x > 0:
x,y = x // y, y
yield x
a = [i for i in int_div(x,y)]
print("number of divison:{}".format(len(a)))