I am new to Python programming. Therefore I know that this question will be very basic to some. My problem is that python throws an error global name 'firstRollValue' is not defined at compile. I have written small programs from online tutorials with similar constructs that work fine (i.e. calling a function from a function). I know there are far more concise ways to write a similar program, but I am attempting to gauge my understanding of functions and return values. How should I define variables, such as firstRollValue so that this program runs?
import random
def test_craps_Game():
firstRoll()
assessFirstRoll()
rollForPoint()
def firstRoll():
firstRollValue = random.choice([1, 2, 3, 4, 5, 6]) + random.choice([1, 2, 3, 4, 5, 6])
return firstRollValue
def assessFirstRoll():
if firstRollValue == [2, 3, 12]:
print 'You rolled ' + firstRollValue + '. ' + '\nYou Lose!'
elif firstRollValue == [7, 11]:
print 'You rolled ' + firstRollValue + '. ' + '\nYou Win!'
else:
shooterHasPoint = True
shooterPoint = firstRollValue
print 'Your point is ' + shooterPoint
return shooterPoint
def rollForPoint():
shooterHasPoint = True
while shooterHasPoint == True:
lastRollValue = random.choice([1, 2, 3, 4, 5, 6]) + random.choice([1, 2, 3, 4, 5, 6])
if lastRollValue == shooterPoint:
print 'You rolled ' + lastRollValue + ' your point, ' + 'You Win!'
shooterResult = 'Shooter Wins'
shooterHasPoint = False
elif lastRollValue == 7:
print 'You crapped ' + lastRollValue + ' you lose.'
shooterResult = 'Shooter Loses'
shooterHasPoint = False
return shooterResult