Monday, July 25, 2011

Python dice roll code example

#dice roll function (6-sided by default)
import random

def roll(d=6):
     return random.randint(1, d)
while 1 > 0 :
   
    a=raw_input("enter number 1-6 : ")
    b=int(a)
    print ("entered :" , b)
    c=roll()
    print ("received :" , c)
    if (c == b):
        print ("you win ")
        break
    else :
        print ("you loose " , b , " <> ", c)
        print ("---------------------")



what does break do?
What is the use of random ?

======================

1 comment: