[Python Wpg] Door prize draw

Michael Hohner m.hohner at uwinnipeg.ca
Fri Oct 26 09:20:25 EDT 2007


Mike;

Slight improvement:

U-of-Ws-Computer:~ mhohner$ diff prize_orig.py prize.py 
0a1,2
> import random
> 
52c54
<       award = int(random() * (name_count + 1))
---
>       award = int(random.random() * (name_count + 1))

Otherwise I get:

  File "prize.py", line 52, in ?
    award = int(random() * (name_count + 1))
NameError: name 'random' is not defined

Thanks! - neat idea!

Cheers,

Michael



 

Michael Hohner,
Systems & Media Services Coordinator
University of Winnipeg Library

VOICE: (204) 786-9812
FAX: (204) 783-8910
EMAIL: m.hohner at uwinnipeg.ca
WEB: http://library.uwinnipeg.ca/



>>> Mike Pfaiffer <high.res.mike at gmail.com> 10/25/07 3:53 PM >>> 
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]
_______________________________________________
Winnipeg mailing list
Winnipeg at python.org
http://mail.python.org/mailman/listinfo/winnipeg





More information about the Winnipeg mailing list