I am new to generators and I am trying to make the below code work where my generator should send a random number to my function and check if it matches the target and return the number of count to make this match, when I run the code it justs stops iteration, where am I going wrong?
def generator(min_val: int, max_val: int) -> Iterator[int]:
yield random.randint(min_val,max_val)
def find_target(target: int, min_val: int=0, max_val: int=10, max_attempts: int=100):
i=1
cnt=1
g = generator(0,10)
while i<100:
a = next(g)
if g==target:
return cnt
else:
cnt+=1
i+=1
if i >=100:
return None
Aucun commentaire:
Enregistrer un commentaire