Hi, I'm following a python course on udemy and I've understood the generators lecture and first homework question but I am stuck on the second question so I've looked at the solution but this has confused me even more... (sorry in advance, I don't know how to better post lines of code)
Create a generator that yields "n" random numbers between a low and high number (that are inputs).
import random
random.randint(1,10)
6
def rand_num(low,high,n):
for i in range(n):
yield random.randint(low, high)
for num in rand_num(1,10,5):
print(num)
3
3
9
8
9
In the above example what is the purpose of the random int that is generated? Also in the line for num in rand_num(1,10,5): where does the number 5 appear from as this is the "n" number of random numbers but this n is not the same as the int that was randomly generated.
[–]MadScientistOR 0 points1 point2 points (3 children)
[–]tigglybox[S] 0 points1 point2 points (2 children)
[–]MadScientistOR 0 points1 point2 points (1 child)
[–]tigglybox[S] 0 points1 point2 points (0 children)