Re: [Tutor] Trying to access a random value in a list

2012-01-15 Thread lina
On Fri, Jan 13, 2012 at 6:48 AM, Claude Matherne wrote: > Hello all, > I am a beginner to python and I am trying to make a simple program that > takes in some names as input into a list and then randomly picks a vaule > from that list as a winner. > > Here is the code: > > import random > > choice

Re: [Tutor] Trying to access a random value in a list

2012-01-13 Thread Steven D'Aprano
On 13/01/12 10:56, Nick W wrote: first problem: easy fix just remember that len() returns the actual number of items in the list but that list is indexed starting at 0 so just replace your line of pick = len(names) with: pick = len(names) - 1 Another good trick for choosing a

Re: [Tutor] Trying to access a random value in a list

2012-01-12 Thread Dave Angel
On 01/12/2012 06:56 PM, Nick W wrote: first problem: easy fix just remember that len() returns the actual number of items in the list but that list is indexed starting at 0 so just replace your line of pick = len(names) with: pick = len(names) - 1 and for problem #2: just use str

Re: [Tutor] Trying to access a random value in a list

2012-01-12 Thread bob gailer
On 1/12/2012 5:48 PM, Claude Matherne wrote: Hello all, I am a beginner to python and I am trying to make a simple program that takes in some names as input into a list and then randomly picks a vaule from that list as a winner. Here is the code: import random choice = None names = [ ] while c

Re: [Tutor] Trying to access a random value in a list

2012-01-12 Thread Nick W
first problem: easy fix just remember that len() returns the actual number of items in the list but that list is indexed starting at 0 so just replace your line of pick = len(names) with: pick = len(names) - 1 and for problem #2: just use string formating... like for example instead