Need help on program!!!

Max M maxm at mxm.dk
Fri Dec 3 14:06:41 EST 2004


Dan Perl wrote:
> That was also my impression.  Even the description of the problem looks like 
> it's just copied from the assignment, so probably didn't even take the time 
> to restate the problem in his own words.
> 
> But we're speculating.  Either way, this is not a normal request: "I need a 
> program to do this, plz help!"  To the OP: you can't seriously expect us to 
> actually write the program for you, what kind of help are you looking for?

This?


# -*- coding: latin-1 -*-

"""
   a.. Play a dice game of Craps using a random number generator to simulate
the roll of the dice, the code for the rolling of the dice should take place
in a user written module named rolldice.

   b.. The rules of the game are as follows:
     a.. 1st roll, a score of 7 or 11 wins.
     b.. 1st roll, a score of 2, 3, or 12 loses.
     c.. 1st roll, any number other than those listed above becomes the goal
number, you must keep rolling until you roll the goal number again.  If a 7
is rolled before you goal number, you lose.
"""

import random

def rolldice():
     dice1, dice2 = random.randint(1,6), random.randint(1,6)
     print dice1, dice2
     return dice1, dice2

first1, first2 = rolldice()
first = first1, first2
roll = 1
if first in (7, 11):
     print 'Congratulations, you win in roll %s' % roll
elif first in (2,3,7):
     print 'Too bad, you loose in roll %s' % roll
result = 'draw'
while result == 'draw':
     dice1, dice2 = rolldice()
     roll += 1
     if dice1 + dice2 == 7:
         print 'Too bad, you loose in roll %s' % roll
         result = None
     elif (dice1, dice2) == (first1, first2):
         print 'Congratulations, you win in roll %s' % roll
         result = None


Hopefully his teacher doesn't know about Google, or he can be expelled 
from school for using it.

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science



More information about the Python-list mailing list