Reputation: 11
I need the randomList
function parameters to be:
Im not sure what I am doing wrong. Any help appreciated.
from random import randrange
import random
def randomList(x,y,z):
myList = []
for x in range(x, y, z):
myList.append(random.randrange(x, y, z))
print(myList)
randomList(1, 5, 1)
Upvotes: 0
Views: 45
Reputation: 217
For this question I assumed that x
would be the amount of numbers added to myList
and that y
and z
would be the minimum and maximums. Using that information I got this code: it iterates x
amount of times and each time appends(adds) an integer from (1, 5)
.
from random import randrange
import random
def randomList(x,y,z):
myList = []
for i in range(x):
myList.append(random.randrange(y, z))
print(myList)
randomList(5, 1, 6)
This would give 5 random numbers, that have a minimum value of 1 (y
) and a maximum of 5(z
)(z is exclusive).
The output would look something like the following:
[1, 5, 2, 5, 2]
Upvotes: 1