[Python Wpg] Door prize draw

Mike Pfaiffer high.res.mike at gmail.com
Thu Oct 25 16:53:08 EDT 2007


	I was feeling a little more like doing something today. So I whipped up 
a quick and dirty door prize draw program (no need to go crazy with it). 
Save the text to prize.py. Here is the source. If I can resolve my 
problems with Shaw it will be posted there too. Enjoy.

				Later
				Mike

P.S. Produced on a Mac Mini with Textwrangler.

---------------------
# This program distributes door prizes for clubs

# Import modules as needed
from random import seed, random

# Seed random number generator
seed()

# Print introductory message
print """Door prize distribution program:

This program will distribute a number of door prizes to all people who
enter their names in to this program. The program presumes no errors
in data entry.

Note: to collect the prize the person must actually be present.

The first step is to enter the prizes and the second is to enter the names
of the people participating in the draw. The third will be the actual draw.

"""

# Enter prizes
prize_count = -1
print "Enter prize list. Terminate with 'end'."
print
prize = ''
while (prize != 'end'):
      prize = raw_input('Prize --> ')
      if prize != 'end':
           prize_count = prize_count + 1
           if prize_count == 0:
                prize_list = [prize]
           else:
                prize_list = prize_list + [prize]
      else:
           print "Prize entry terminated."
           print

# List prizes
print "Prize list:"
for counter in range(prize_count + 1):
      print prize_list[counter]
print

# Enter names
name_count = -1
print "Enter names. Terminate with 'end'."
print
name = ''
while name != 'end':
      name = raw_input('Name --> ')
      if name != 'end':
           name_count = name_count + 1
           template = [name, 'no prize']
           if name_count == 0:
                name_list = [template]
           else:
                name_list = name_list + [template]
      else:
           print "Name entry terminated."
           print

# List names
print "Name list:"
for counter in range(name_count + 1):
      print name_list[counter][0]
print

# Award prizes
print "The prizes go to..."
counter = 0
while counter <= (prize_count):
      award = int(random() * (name_count + 1))
      if name_list[award][1] == 'no prize':
           name_list[award][1] = prize_list[counter]
           counter = counter + 1

# Display results
for counter in range(name_count + 1):
      print name_list[counter]



More information about the Winnipeg mailing list