+ 1

I'm getting just one random value whenever i call this function instead of 5

def random_values(x,y,z): import random for i in range(x): value = random.randint(y,z) return value print(random_values(5,1,6))

15th Sep 2019, 7:14 AM
Onimisi
Onimisi - avatar
5 Answers
+ 4
Sonny Walker your code gives 'value' another value each time in loop, then returns the last value. using print it will print the value each time in loop, but if you want to use it you need to make it like ~ swim ~ 's answer
15th Sep 2019, 7:55 AM
Sousou
Sousou - avatar
+ 2
Ok but i when i used the print instead of the return function i get it correct. Does that mean when using the print function i don't need to make value a list def random_values(x,y,z): import random for i in range(x): value = random.randint(y,z) print(value) random_values(5,16)
15th Sep 2019, 7:44 AM
Onimisi
Onimisi - avatar
+ 2
Ok thanks i understand a bit better now ~ swim ~ :)
15th Sep 2019, 7:56 AM
Onimisi
Onimisi - avatar