while and if
Satchidanand Haridas
sharidas at zeomega.com
Fri Aug 13 00:54:13 EDT 2004
Calvin79 wrote:
>Hi,
>
>I'm very new to python, but believe in learning from examples. So could
>someone please help me with this?
>
>I choose a number of 'things' I want
>
>Number = input("Number of things (1-8)? ")
>things = ['1', '2', '3', '4', '5', '6', '7',\
>'8']
>
>>From there I want to take at random a letter and do this n times depending
>on the number I gave.
>
>choice = choice('abcd')
>
>The final answer if say the number had been 5 to look something like;
>
>choice 1 = d
>choice 2 = c
>choice 3 = a
>choice 4 = d
>choice 5 = b
>etc...
>
>I can sort of see how to use the while loop for int but not to keep
>choosing from the list and lable it choice 1 etc...
>
>Thanks for any help,
>
>Calvin
>
>
>
The following code does what I think you want to do:
<code>
import random
things = range(int(raw_input("Number of things (1-8)? ")))
for x in things:
print "choice ",x+1, " is ", random.choice('abcd')
</code>
Regards,
Satchit
----
Satchidanand Haridas (sharidas at zeomega dot com)
ZeOmega (www.zeomega.com)
Open Minds' Open Solutions
#20,Rajalakshmi Plaza,
South End Road,
Basavanagudi,
Bangalore-560 004, India
More information about the Python-list
mailing list