Pick random choice from variables

E

eli m

How do i make something with python that will ask the user for input, and then use the random.choice function to select a random choice from what the user entered.
 
J

Joel Goldstick

How do i make something with python that will ask the user for input, and
then use the random.choice function to select a random choice from what the
user entered.
l = [1,2,3] # or any list

r = random.choice(l)
 
D

David Hutto

Below is a snippet example:

import random as rand

selection_enter = raw_input("Enter Selection List of Three Items
Seperated By Commas: ")

selection_list = selection_enter.split(",")

print selection_list

rand_choice = rand.choice(selection_list)

print rand_choice
 
D

David Hutto

The first one I sent directly to you, but it used randint with a list.
The second should be what you're looking for. If not, then ask a
little further what you need explained.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top