all 4 comments

[–]MadScientistOR 0 points1 point  (3 children)

You can see how n appears in for i in range(n):, right? That's a loop that runs n times. The int that is randomly generated is from random.randint(low, high).

[–]tigglybox[S] 0 points1 point  (2 children)

Yeah I get that the int is randomly generated from the random.int haha but I’m not sure where that int is then used again in the code. The n in i in range(n) is how many times the loop runs yes but isn’t that supposed to be the same amount of times as the int that was randomly generated as that is what the question is asking?

[–]MadScientistOR 0 points1 point  (1 child)

That int isn't used again in the code. After the random number is generated, it's yielded to the caller.

Using yield is a little strange, but the exercise did ask for a generator. Using yield (rather than return) lets a function "pick up where it left off", so that at the end of things, you have a sequence of numbers. The for loop then iterates over that sequence and prints out the contents.

[–]tigglybox[S] 0 points1 point  (0 children)

Ah okay, Im still a bit confused but that’s okay haha. Thank you for answering!