+ 1
Hey guys, pls help me with this code, I want it to choose a random number and it's not
seats =[1, 2 ,3,4,5,6,7,8,9,10] seats2 = random.choice(seats) print(str(seats2))
4 Answers
+ 3
It works
https://code.sololearn.com/c96Xb7H3s2T4/?ref=app
try this too (one liner)
https://code.sololearn.com/ciuRsd28y0X1/?ref=app
+ 3
Zanele ,
your code is missing the import of the module *random*:
from random import choice
seats =[1, 2 ,3,4,5,6,7,8,9,10]
seats2 = choice(seats)
print(str(seats2)) # no need to convert to string
# when using a consecutive range of numbers, also randint() can be used
from random import randint
seats2 = randint(1, 10)
print(seats2)
+ 1
I was missing import random
0
Thank you