0

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
Skillionaire
  • 83
  • 2
  • 6
  • Briefly: you need to save the returned values. I recommend taking a look at the [official Python tutorial](https://docs.python.org/3.6/tutorial/index.html). – TigerhawkT3 Jan 07 '17 at 07:49
  • get value from one function `result = firstRoll()` and then send to anothers `assessFirstRoll(result)` and `rollForPoint(result)` but they need `def assessFirstRoll(firstRollValue):` and `def rollForPoint(firstRollValue):` – furas Jan 07 '17 at 08:00
  • Python doesn't compile, it interprets. – FMaz Jan 07 '17 at 09:59
  • @furas I just want to send a brief thanks for clarifying how to pass a return value to another functions variables. I have a very basic implementation of a very basic craps game simulator coded, thank partly to you. Much appreciated. Also thanks Krazor and TigerhawkT3 for replying to the rudimentary question. – Skillionaire Jan 17 '17 at 23:29

0 Answers0