0

Can anyone upload coding for inserting a list of random numbers? I can't get the imported 'random' to output the numbers as list

It seems as though random is designed to output vertically. import random for i in range(5):    value = random.randint(1, 6)    print(value) result: >>> 2 3 6 5 4 >>>

7th Mar 2018, 11:18 AM
Msizi
6 Respuestas
+ 8
Also, why not use a real list. import random list = [] for i in range(5): list.append(random.randint(1, 6)) print(list)
7th Mar 2018, 1:14 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
print() automatically appends a newline to what you pass into the method. To prevent this, do print(value, end= ' ')
7th Mar 2018, 1:12 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
from random import randint print([randint(1, 6) for i in range(5)]) or, if you don't want the brackets and commas: print(*[randint(1, 6) for i in range(5)])
10th Mar 2018, 11:29 AM
David Ashton
David Ashton - avatar
0
Allas. Please do show me nonetheless. Would appreciate it if you could get somoene to help me to get this right in python.
7th Mar 2018, 11:55 AM
Msizi
0
Thanks
7th Mar 2018, 1:13 PM
Msizi
0
sir, can you please explain me this one ? why I have index error in second case but not the first case. import numpy as np lambda_range = np.arange(500.1, 2000.1, 20) print(lambda_range[2]) nm = 1e-9 lambda1 = 500*nm lambda2 = 2000*nm lambda_range = np.arange(lambda1, lambda2, 20) print(lambda_range[2])
11th Mar 2018, 11:19 AM
Vishal Vashistha
Vishal Vashistha - avatar