random.seed() established a pointer in a table of randomly generated numbers. It's just part of a random number generation routine to simulate rolling two dice.
If you just add a number to Total_1 = itll come up saying whatever, problem is, Total (from dice_roll) isnt defined.. Define it..
I know HOW it needs to be fixed, i just dont "know" the code.. sigh, im gonna learn this shit now. lmfao.. 7am and im learning a new language.. good times.. thanks Q3W
[size=75][i]I once had a glass of milk.
It curdled, and then I couldn't drink it. So I mixed it with some water, and it was alright again.
I am now sick.
[/i][/size]
[img]http://img162.imageshack.us/img162/3631/171164665735hk8.png[/img]
hey nightshade.. thanks for this thread.. think i might really enjoy python.. ill keep fucking with this craps thing after work, post or PM me if you get it working before i do, id like to know the solution..
[size=75][i]I once had a glass of milk.
It curdled, and then I couldn't drink it. So I mixed it with some water, and it was alright again.
I am now sick.
[/i][/size]
[img]http://img162.imageshack.us/img162/3631/171164665735hk8.png[/img]
#Craps_Game
import random
random.seed()
def roll_dice():
r1 = random.random()
Die_1 = int(6 * r1) +1
r2 = random.random()
Die_2 = int(6 * r2) + 1
Total = Die_1 + Die_2
return(Total)
Total = roll_dice()
Total_1 = Total
if(Total_1 == 7) or (Total_1 == 11):
print "Lucky ", Total_1, "! You win!"
elif(Total_1 == 2) or (Total_1 == 3) or (Total_1 == 12):
print Total_1, "CRAPS! You lose!"
else:
Total = roll_dice()
Total_2 = Total
roll_count = 0
while(roll_count < 20):
if(Total_2 == Total_1):
Total = roll_dice()
Total_2 = Total
elif(Total_2 == 7):
print "Lucky ", Total_2, "! You win!"
It keeps telling me that Total isn't defined.
Well it's right.
The function roll_dice returns a value (number, whatever) that you need to assign to the variable Total.
Like this:
Total = roll_dice()
What you're doing is simply calling the function (which returns a value) but you're not doing anything with it (you're not storing it in a variable). The definition of the variable Total in the function roll_dice is not public, so it's expected that the bottom part doesn't know it.
edit: fixed the code (with all three calls to roll_dice()) in the quote, I'm not going to bother with the rest but if you need any help just ask.
Seems to work now, just downloaded python and ran the program.
Tip though: you can assign the value of roll_dice directly to total_1, total_2 and total_3 instead of assigning it to Total and then to the other 3.
Just out of interest: what are you using python for? Educational purpose? (never heard of it, actually had to google it to find out what it is).
Last edited by phoq on Fri Apr 08, 2005 1:05 pm, edited 1 time in total.
phoq wrote:
Well it's right.
The function roll_dice returns a value (number, whatever) that you need to assign to the variable Total.
Like this:
Total = roll_dice()
What you're doing is simply calling the function (which returns a value) but you're not doing anything with it (you're not storing it in a variable). The definition of the variable Total in the function roll_dice is not public, so it's expected that the bottom part doesn't know it.
edit: fixed the code (with all three calls to roll_dice()) in the quote, I'm not going to bother with the rest but if you need any help just ask.
Yeah, I had the call fucked up, which I suspected from the beginning. Thanks.
Hey GothBoi, glad you like Python, hope it makes up for me shooting your dad.