- 1
Please help!!
names=['Ralph','David','Donald','Susan'] How do you use random, so that each time u print that code it gives u a completely random output from the list above . I do know that u have to import "random" module but I'm unsure how to use the random in a statement
7 odpowiedzi
+ 6
import this
+ 3
you can also use random.choice (names)
import random
names = your list
print (random.choice (names))
+ 1
import random
names=['Ralph','David','Donald','Susan']
random.seed()
r = random.randint(0, len(names))
print(names[r])
+ 1
wow.....thanks Luke, shorter but still gets the job done .
0
Thank you Zen .....worked like a charm
0
👐♓🅰🌴?
0
zen, why it printed "unexpected token import?" Thanks in advance for answering! Pls, dont critic me, im just started learning js