[Tutor] Repeating a routine
John Connors
oztriking at hotmail.com
Thu Feb 23 02:59:13 CET 2006
G'day,
I think my peanut sized brain is starting to understand how to do this. I
tried with a simple dice game where 4 dice are rolled, if the total of the
last 2 dice rolled is 6 you win. It's kinda pointless using 4 dice rolls
when only 2 are needed but I wanted to prove to myself I could call the dice
function whenever I needed it.
This is what I came up with.
import random
def dice():
return random.randint(1,6)
playagain = 'y'
while playagain == 'y':
die1 = dice()
die2 = dice()
print '1st dice is ',die1,'\n','2nd dice is ',die2
die3 = dice()
die4 = dice()
winnum = die3 + die4
print'combined total for the next 2 dice is ',winnum
if winnum == 6:
print 'you win'
else:
print 'you lose'
playagain = raw_input('play again? (y/n) ')
print 'goodbye'
_________________________________________________________________
Make your dream car a reality
http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fcarpoint%2Eninemsn%2Ecom%2Eau&_t=12345&_r=emailtagline&_m=EXT
More information about the Tutor
mailing list