Python Forum
Random selection from list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random selection from list
#2
print() returns None, so p_ask = print() doesn't do anything useful
x = print('Hi')
print(x)
Output:
None
Your use of random.choices was correct until you joined all the ask elements into a string.
import random
ask = ('Is', 'Do', 'Does', 'Are')
print(random.choices(ask, k=2))
Output:
['Do', 'Are']
My guess though is that you didn't want a list of choices, but a single choice:
import random
ask = ('Is', 'Do', 'Does', 'Are')
print(random.choice(ask))
Output:
Does
Reply


Messages In This Thread
Random selection from list - by Mohsky - Mar-31-2020, 07:06 PM
RE: Random selection from list - by deanhystad - Mar-31-2020, 10:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  printing list of random generated rectangles Zatoichi 8 7,490 Feb-18-2018, 06:34 PM
Last Post: buran
  bubble sort random list atux_null 7 8,056 Nov-03-2017, 07:28 PM
Last Post: sparkz_alot
  List with Random Numbers AnjyilLee 5 9,512 Oct-14-2017, 09:22 PM
Last Post: buran
  Random Shuffle List simon 10 10,333 Oct-24-2016, 04:02 PM
Last Post: simon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020