0

My code output is broken

import random XYZ = ["yes", "no", "try again", "im confused", "forgetaboutit", "when pigs fly", "your luck would be better spent on a lotto ticket"] print(random.sample(XYZ, 1)) that is my code. why is that out put always inside of [' '] ? the code in the playground: https://code.sololearn.com/cfrVU5beJ4S7/?ref=app

26th Jul 2017, 1:41 AM
vortetty
vortetty - avatar
5 ответов
+ 7
Try print(random.choice(XYZ))
26th Jul 2017, 2:38 AM
David Ashton
David Ashton - avatar
+ 3
This is exactly what it's suposed to do though. sample returns a new list. So, you're just printing a different list. For example, If you wrote: print(XYZ); It would still have those brackets. The brackets are just showing what is inside the list, which is shown when you print a list.
26th Jul 2017, 1:48 AM
Rrestoring faith
Rrestoring faith - avatar
+ 2
Yes. Do what @David said.
26th Jul 2017, 2:12 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
ok! that worked! thank you so much!
26th Jul 2017, 2:49 PM
vortetty
vortetty - avatar
0
is there any way to tell it to not put it in the brackets?
26th Jul 2017, 12:31 PM
vortetty
vortetty - avatar