Need help on program!!!

Brad Tilley rtilley at vt.edu
Fri Dec 3 21:29:55 EST 2004


Darth Haggis wrote:
> I need help writing a program....
> 
> You are to write a python program to accomplish the following:
> 
> 
> 
>   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.
> 
> 
> Make the game continuous, until you tell it to stop.  You can bet the same
> amount, or change you bet after each win or loss.  Print the results of each
> roll and the running total of winnings or loses.
> 
> 
> 
> plz help!!!

Here's everything *except* the betting part. I don't gamble ;)

import random

class rolldice:

     def first(self):

         win = [7,11]
         lose = [2,3,12]
         x = random.randint(1,6)
         y = random.randint(1,6)
         z = x+y
         print x, "+", y, "=", z
         if z in win:
             print "You won on the first roll!!!"
             return 0
         elif z in lose:
             print "You lost on the first roll!!!"
             return 0
         else:
             return z

     def second(self, goal):

         if goal > 0:
             lose = 7
             print "The goal number is:", goal

             while True:
                 x = random.randint(1,6)
                 y = random.randint(1,6)
                 z = x+y
                 print x, "+", y, "=", z
                 if z == lose:
                     print "You lost!!!"
                     return 0
                 elif z == goal:
                     print "You won!!!"
                     return z
                 else:
                     continue

play = rolldice()
play.second(play.first())



More information about the Python-list mailing list