+ 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))
3 Réponses
+ 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
+ 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)
+ 2
Ok thanks i understand a bit better now ~ swim ~ :)