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 >>>
6 Réponses
+ 8
Also, why not use a real list.
import random
list = []
for i in range(5):
list.append(random.randint(1, 6))
print(list)
+ 7
print() automatically appends a newline to what you pass into the method. To prevent this, do
print(value, end= ' ')
+ 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)])
0
Allas. Please do show me nonetheless. Would appreciate it if you could get somoene to help me to get this right in python.
0
Thanks
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])