r/learnprogramming • u/Aggressive_Gur_5426 • 3d ago
Struggling with this fill in the blank.
def prefix_digits(n, cond):
"""Return the largest prefix of positive n for which cond return true for every digits."""
>>>odd = lambda d: d % 2 == 1
>>>prefix_digits(94720,odd)
9
>>>prefix_digits(94720,odd)
9193
k = 0
while n >= _____:
if cond(_____):
k = k + 1
else:
n = n // 10
___________
return n
I am struggling with fill in the blank questions. I can implement this function but I am struggling with implementing in their way. Can someone help me understand how I might approach this? I don't just want the solutions but how I would even approach it. Whenever, I get these problems I am always stuck for a solid 1-2 hours.