- 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

17th Sep 2016, 12:31 PM
steampunk08
steampunk08 - avatar
7 Respostas
+ 6
import this
26th Feb 2020, 7:38 PM
Aksa Khan
Aksa Khan - avatar
+ 3
you can also use random.choice (names) import random names = your list print (random.choice (names))
17th Sep 2016, 11:31 PM
Luke Armstrong
+ 1
import random names=['Ralph','David','Donald','Susan'] random.seed() r = random.randint(0, len(names)) print(names[r])
17th Sep 2016, 1:59 PM
Zen
Zen - avatar
+ 1
wow.....thanks Luke, shorter but still gets the job done .
18th Sep 2016, 3:21 AM
steampunk08
steampunk08 - avatar
0
Thank you Zen .....worked like a charm
17th Sep 2016, 2:07 PM
steampunk08
steampunk08 - avatar
0
👐♓🅰🌴?
18th Sep 2016, 5:49 AM
steampunk08
steampunk08 - avatar
0
zen, why it printed "unexpected token import?" Thanks in advance for answering! Pls, dont critic me, im just started learning js
26th Sep 2016, 8:53 PM
romalemonade
romalemonade - avatar