You write:
lis = list(randreal)
But list(..) is the constructor here. The constructor is looking for an iterable object (another list, set, dictionary, generator, etc.), which can turn into a list. A floating point is not iterable, so a list cannot be created for it. This will result in an error.
One way to solve it is to assign the list index to lis :
lis = [0] * 10 random.seed(70) for i in range(0, len(lis)): randreal = (random.random()*5 + 30) lis [i] = randreal
But this is still not very elegant: first you create a list, and then modify it. You can improve the code by drawing 10 elements and each time .append(..) to the list:
lis = [] random.seed(70) for i in range(0, 10 ): randreal = (random.random()*5 + 30) lis .append( randreal )
This is better, but still with a lot of code, so we can use list comprehension to make it more declarative:
random.seed(70) lis = [random.random()*5 + 30 for _ in range(10)] print(lis)
source share