Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Pick random choice from variables

Reply
Thread Tools

Pick random choice from variables

 
 
eli m
Guest
Posts: n/a
 
      02-10-2013
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.
 
Reply With Quote
 
 
 
 
Joel Goldstick
Guest
Posts: n/a
 
      02-10-2013
On Sun, Feb 10, 2013 at 12:01 PM, eli m <> wrote:

> 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)

> --
> http://mail.python.org/mailman/listinfo/python-list
>




--
Joel Goldstick
http://joelgoldstick.com

 
Reply With Quote
 
 
 
 
David Hutto
Guest
Posts: n/a
 
      02-10-2013
On Sun, Feb 10, 2013 at 12:43 PM, Joel Goldstick
<> wrote:
>
>
>
> On Sun, Feb 10, 2013 at 12:01 PM, eli m <> wrote:
>>
>> 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.

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

--
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
 
Reply With Quote
 
David Hutto
Guest
Posts: n/a
 
      02-10-2013
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
Multiple Choice Test - Pick The Anti-Virus Program Luke O'Malley Computer Support 4 07-25-2007 02:18 AM
When to pick quad core and when to pick dual core thingy NZ Computing 6 11-21-2006 07:08 AM
When to pick ASP.Net, when to pick desktop? tom c ASP .Net 5 11-01-2006 06:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57